Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite5753a1

Browse 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 combinethem with the data fetched from Read the Docs API, I realized that if we aremigrating only _one_ version to Read the Docs and using a proxy to serve it atthe official `docs.python.org` domain, there is no need to use a differentversion/language selector at all --since all the URLs will be the same and all theJavaScript logic will be the same. The proxy will do the magic to redirect toRead 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 JavaScriptwhen the page is served.Do we have a JSON file from where we can populate the `LANGUAGES` variable?I'm opening a PR here to show what I'm thinking and discuss if this is theapproach we want to follow. BTW, the code is not tested. I just wrote it as anexample 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'trequire the `release-cycle.json` nor other file to populate the `LANGUAGES`variable because this data will come from Read the Docs Addons API.
1 parent2135304 commite5753a1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

‎templates/switchers.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(){
1+
(asyncfunction(){
22
'use strict';
33

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

21-
constall_versions=$VERSIONS;
21+
// Fetch all available documentation versions from `release-cycle.json`
22+
constreleaseCycleURL="https://raw.githubusercontent.com/python/devguide/main/include/release-cycle.json";
23+
constreleaseCycleResponse=awaitfetch(releaseCycleURL,{method:"GET"});
24+
if(!releaseCycleResponse.ok){
25+
thrownewError("Error downloading release-cycle.json file.");
26+
}
27+
constreleaseCycleData=awaitreleaseCycleResponse.json();
28+
29+
constall_versions=newArray();
30+
for(constversionofreleaseCycleData){
31+
all_versions.push(version);
32+
}
33+
// TODO: fetch available languges from an external JSON file
2234
constall_languages=$LANGUAGES;
2335

2436
functionquote_attr(str){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp