Skip to content

Commit f2dc999

Browse files
committed
[3.12] Docs: remove temporary hardcoded links (pythonGH-120348)
(cherry picked from commit b8484c6) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent f774d49 commit f2dc999

File tree

2 files changed

+57
-85
lines changed

2 files changed

+57
-85
lines changed

Doc/tools/static/rtd_switcher.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function onSwitch(event) {
2+
const option = event.target.selectedIndex;
3+
const item = event.target.options[option];
4+
window.location.href = item.dataset.url;
5+
}
6+
7+
document.addEventListener("readthedocs-addons-data-ready", function(event) {
8+
const config = event.detail.data()
9+
const versionSelect = `
10+
<select id="version_select">
11+
${ config.versions.active.map(
12+
(version) => `
13+
<option
14+
value="${ version.slug }"
15+
${ config.versions.current.slug === version.slug ? 'selected="selected"' : '' }
16+
data-url="${ version.urls.documentation }">
17+
${ version.slug }
18+
</option>`
19+
).join("\n") }
20+
</select>
21+
`;
22+
23+
// Prepend the current language to the options on the selector
24+
let languages = config.projects.translations.concat(config.projects.current);
25+
languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name));
26+
27+
const languageSelect = `
28+
<select id="language_select">
29+
${ languages.map(
30+
(translation) => `
31+
<option
32+
value="${ translation.slug }"
33+
${ config.projects.current.slug === translation.slug ? 'selected="selected"' : '' }
34+
data-url="${ translation.urls.documentation }">
35+
${ translation.language.name }
36+
</option>`
37+
).join("\n") }
38+
</select>
39+
`;
40+
41+
// Query all the placeholders because there are different ones for Desktop/Mobile
42+
const versionPlaceholders = document.querySelectorAll(".version_switcher_placeholder");
43+
for (placeholder of versionPlaceholders) {
44+
placeholder.innerHTML = versionSelect;
45+
let selectElement = placeholder.querySelector("select");
46+
selectElement.addEventListener("change", onSwitch);
47+
}
48+
49+
const languagePlaceholders = document.querySelectorAll(".language_switcher_placeholder");
50+
for (placeholder of languagePlaceholders) {
51+
placeholder.innerHTML = languageSelect;
52+
let selectElement = placeholder.querySelector("select");
53+
selectElement.addEventListener("change", onSwitch);
54+
}
55+
});

Doc/tools/templates/layout.html

+2-85
Original file line numberDiff line numberDiff line change
@@ -46,90 +46,7 @@
4646
{{ super() }}
4747

4848
{%- if not embedded %}
49-
<meta name="readthedocs-addons-api-version" content="1">
50-
<script type="text/javascript">
51-
function onSwitch(event) {
52-
const option = event.target.selectedIndex;
53-
const item = event.target.options[option];
54-
window.location.href = item.dataset.url;
55-
}
56-
57-
document.addEventListener("readthedocs-addons-data-ready", function(event) {
58-
const config = event.detail.data()
59-
60-
// Add some mocked hardcoded versions pointing to the official
61-
// documentation while migrating to Read the Docs.
62-
// These are only for testing purposes.
63-
// TODO: remove them when managing all the versions on Read the Docs,
64-
// since all the "active, built and not hidden" versions will be shown automatically.
65-
let versions = config.versions.active.concat([
66-
{
67-
slug: "dev (3.13)",
68-
urls: {
69-
documentation: "https://docs.python.org/3.13/",
70-
}
71-
},
72-
{
73-
slug: "3.12",
74-
urls: {
75-
documentation: "https://docs.python.org/3.12/",
76-
}
77-
},
78-
{
79-
slug: "3.11",
80-
urls: {
81-
documentation: "https://docs.python.org/3.11/",
82-
}
83-
},
84-
]);
85-
86-
const versionSelect = `
87-
<select id="version_select">
88-
${ versions.map(
89-
(version) => `
90-
<option
91-
value="${ version.slug }"
92-
${ config.versions.current.slug === version.slug ? 'selected="selected"' : '' }
93-
data-url="${ version.urls.documentation }">
94-
${ version.slug }
95-
</option>`
96-
).join("\n") }
97-
</select>
98-
`;
99-
100-
// Prepend the current language to the options on the selector
101-
let languages = config.projects.translations.concat(config.projects.current);
102-
languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name));
103-
104-
const languageSelect = `
105-
<select id="language_select">
106-
${ languages.map(
107-
(translation) => `
108-
<option
109-
value="${ translation.slug }"
110-
${ config.projects.current.slug === translation.slug ? 'selected="selected"' : '' }
111-
data-url="${ translation.urls.documentation }">
112-
${ translation.language.name }
113-
</option>`
114-
).join("\n") }
115-
</select>
116-
`;
117-
118-
// Query all the placeholders because there are different ones for Desktop/Mobile
119-
const versionPlaceholders = document.querySelectorAll(".version_switcher_placeholder");
120-
for (placeholder of versionPlaceholders) {
121-
placeholder.innerHTML = versionSelect;
122-
let selectElement = placeholder.querySelector("select");
123-
selectElement.addEventListener("change", onSwitch);
124-
}
125-
126-
const languagePlaceholders = document.querySelectorAll(".language_switcher_placeholder");
127-
for (placeholder of languagePlaceholders) {
128-
placeholder.innerHTML = languageSelect;
129-
let selectElement = placeholder.querySelector("select");
130-
selectElement.addEventListener("change", onSwitch);
131-
}
132-
});
133-
</script>
49+
<script type="text/javascript" src="{{ pathto('_static/rtd_switcher.js', 1) }}"></script>
50+
<meta name="readthedocs-addons-api-version" content="1">
13451
{%- endif %}
13552
{% endblock %}

0 commit comments

Comments
 (0)