Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a2e3a8

Browse filesBrowse files
committed
Generate version selector dynamically via JavaScript
_Note this is just a proof of concept to start the conversation._ While working on the idea to generate the version/language selectors and combine them with the data fetched from Read the Docs API, I realized that if we are migrating only _one_ version to Read the Docs and using a proxy to serve it at the official `docs.python.org` domain, there is no need to use a different version/language selector at all --since all the URLs will be the same and all the JavaScript logic will be the same. The proxy will do the magic to redirect to Read the Docs _only_ the versions configured in the proxy [^1]. However, since when building on Read the Docs the variables `VERSIONS` and `LANGUAGES` are not passed, we need to populate them dynamically with JavaScript when the page is served. - Populate `all_languages` in the same way. Do we have a JSON file from where we can populate the `LANGUAGES` variable? - Move this `switchers.js` file to https://github.com/python/cpython/tree/main/Doc/tools/static ---- I'm opening a PR here to show what I'm thinking and discuss if this is the approach we want to follow. BTW, the code is not tested. I just wrote it as an example to show what I'm thinking is the direction. Related: - python/python-docs-theme#193 - python/docs-community#5 [^1]: Once all the versions/languages are migrated to Read the Docs, we won't require the `release-cycle.json` nor other file to populate the `LANGUAGES` variable because this data will come from Read the Docs Addons API.
1 parent 2135304 commit 0a2e3a8
Copy full SHA for 0a2e3a8

File tree

1 file changed

+14
-2
lines changed
Filter options

1 file changed

+14
-2
lines changed

‎templates/switchers.js

Copy file name to clipboardExpand all lines: templates/switchers.js
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function() {
1+
(async function() {
22
'use strict';
33

44
if (!String.prototype.startsWith) {
@@ -18,7 +18,19 @@
1818
'(?:dev)',
1919
'(?:release/\\d.\\d[\\x\\d\\.]*)'];
2020

21-
const all_versions = $VERSIONS;
21+
// Fetch all available documentation versions from `release-cycle.json`
22+
const releaseCycleURL = "https://raw.githubusercontent.com/python/devguide/main/include/release-cycle.json";
23+
const releaseCycleResponse = await fetch(releaseCycleURL, { method: "GET"});
24+
if (!releaseCycleResponse.ok) {
25+
throw new Error("Error downloading release-cycle.json file.");
26+
}
27+
const releaseCycleData = await releaseCycleResponse.json();
28+
29+
const all_versions = new Array();
30+
for (const version of releaseCycleData ) {
31+
all_versions.push(version);
32+
}
33+
// TODO: fetch available languges from an external JSON file
2234
const all_languages = $LANGUAGES;
2335

2436
function quote_attr(str) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.