summaryrefslogtreecommitdiffstats
path: root/Doc/tools
diff options
context:
space:
mode:
authorJulien Palard <julien@palard.fr>2020-11-07 11:28:31 (GMT)
committerGitHub <noreply@github.com>2020-11-07 11:28:31 (GMT)
commitee2549c2ba8bae00f2b2fea8a39c6dfbd1d06520 (patch)
tree92476e3944b652398732e09e64c3893759e68b17 /Doc/tools
parent825ac383327255d38b69a753e5e41710bb3ed010 (diff)
downloadcpython-ee2549c2ba8bae00f2b2fea8a39c6dfbd1d06520.zip
cpython-ee2549c2ba8bae00f2b2fea8a39c6dfbd1d06520.tar.gz
cpython-ee2549c2ba8bae00f2b2fea8a39c6dfbd1d06520.tar.bz2
bpo-41028: Doc: Move switchers to docsbuild-scripts. (GH-20969)
Diffstat (limited to 'Doc/tools')
-rw-r--r--Doc/tools/static/switchers.js156
-rw-r--r--Doc/tools/templates/dummy.html9
-rw-r--r--Doc/tools/templates/indexsidebar.html8
-rw-r--r--Doc/tools/templates/layout.html10
4 files changed, 12 insertions, 171 deletions
diff --git a/Doc/tools/static/switchers.js b/Doc/tools/static/switchers.js
deleted file mode 100644
index 1a1c7d0..0000000
--- a/Doc/tools/static/switchers.js
+++ /dev/null
@@ -1,156 +0,0 @@
-(function() {
- 'use strict';
-
- // Parses versions in URL segments like:
- // "3", "dev", "release/2.7" or "3.6rc2"
- var version_regexs = [
- '(?:\\d)',
- '(?:\\d\\.\\d[\\w\\d\\.]*)',
- '(?:dev)',
- '(?:release/\\d.\\d[\\x\\d\\.]*)'];
-
- var all_versions = {
- '3.10': 'dev (3.10)',
- '3.9': 'pre (3.9)',
- '3.8': '3.8',
- '3.7': '3.7',
- '3.6': '3.6',
- '2.7': '2.7',
- };
-
- var all_languages = {
- 'en': 'English',
- 'fr': 'French',
- 'ja': 'Japanese',
- 'ko': 'Korean',
- 'pt-br': 'Brazilian Portuguese',
- 'zh-cn': 'Simplified Chinese',
- };
-
- function build_version_select(current_version, current_release) {
- var buf = ['<select>'];
-
- $.each(all_versions, function(version, title) {
- buf.push('<option value="' + version + '"');
- if (version == current_version)
- buf.push(' selected="selected">' + current_release + '</option>');
- else
- buf.push('>' + title + '</option>');
- });
-
- buf.push('</select>');
- return buf.join('');
- }
-
- function build_language_select(current_language) {
- var buf = ['<select>'];
-
- $.each(all_languages, function(language, title) {
- if (language == current_language)
- buf.push('<option value="' + language + '" selected="selected">' +
- all_languages[current_language] + '</option>');
- else
- buf.push('<option value="' + language + '">' + title + '</option>');
- });
- if (!(current_language in all_languages)) {
- // In case we're browsing a language that is not yet in all_languages.
- buf.push('<option value="' + current_language + '" selected="selected">' +
- current_language + '</option>');
- all_languages[current_language] = current_language;
- }
- buf.push('</select>');
- return buf.join('');
- }
-
- function navigate_to_first_existing(urls) {
- // Navigate to the first existing URL in urls.
- var url = urls.shift();
- if (urls.length == 0) {
- window.location.href = url;
- return;
- }
- $.ajax({
- url: url,
- success: function() {
- window.location.href = url;
- },
- error: function() {
- navigate_to_first_existing(urls);
- }
- });
- }
-
- function on_version_switch() {
- var selected_version = $(this).children('option:selected').attr('value') + '/';
- var url = window.location.href;
- var current_language = language_segment_from_url(url);
- var current_version = version_segment_in_url(url);
- var new_url = url.replace('.org/' + current_language + current_version,
- '.org/' + current_language + selected_version);
- if (new_url != url) {
- navigate_to_first_existing([
- new_url,
- url.replace('.org/' + current_language + current_version,
- '.org/' + selected_version),
- 'https://docs.python.org/' + current_language + selected_version,
- 'https://docs.python.org/' + selected_version,
- 'https://docs.python.org/'
- ]);
- }
- }
-
- function on_language_switch() {
- var selected_language = $(this).children('option:selected').attr('value') + '/';
- var url = window.location.href;
- var current_language = language_segment_from_url(url);
- var current_version = version_segment_in_url(url);
- if (selected_language == 'en/') // Special 'default' case for english.
- selected_language = '';
- var new_url = url.replace('.org/' + current_language + current_version,
- '.org/' + selected_language + current_version);
- if (new_url != url) {
- navigate_to_first_existing([
- new_url,
- 'https://docs.python.org/'
- ]);
- }
- }
-
- // Returns the path segment of the language as a string, like 'fr/'
- // or '' if not found.
- function language_segment_from_url(url) {
- var language_regexp = '\.org/([a-z]{2}(?:-[a-z]{2})?/)';
- var match = url.match(language_regexp);
- if (match !== null)
- return match[1];
- return '';
- }
-
- // Returns the path segment of the version as a string, like '3.6/'
- // or '' if not found.
- function version_segment_in_url(url) {
- var language_segment = '(?:[a-z]{2}(?:-[a-z]{2})?/)';
- var version_segment = '(?:(?:' + version_regexs.join('|') + ')/)';
- var version_regexp = '\\.org/' + language_segment + '?(' + version_segment + ')';
- var match = url.match(version_regexp);
- if (match !== null)
- return match[1];
- return ''
- }
-
- $(document).ready(function() {
- var release = DOCUMENTATION_OPTIONS.VERSION;
- var language_segment = language_segment_from_url(window.location.href);
- var current_language = language_segment.replace(/\/+$/g, '') || 'en';
- var version = release.substr(0, 3);
- var version_select = build_version_select(version, release);
-
- $('.version_switcher_placeholder').html(version_select);
- $('.version_switcher_placeholder select').bind('change', on_version_switch);
-
- var language_select = build_language_select(current_language);
-
- $('.language_switcher_placeholder').html(language_select);
- $('.language_switcher_placeholder select').bind('change', on_language_switch);
- });
-})();
diff --git a/Doc/tools/templates/dummy.html b/Doc/tools/templates/dummy.html
index 68ae3ad..3438b44 100644
--- a/Doc/tools/templates/dummy.html
+++ b/Doc/tools/templates/dummy.html
@@ -6,3 +6,12 @@ In extensions/pyspecific.py:
{% trans %}CPython implementation detail:{% endtrans %}
{% trans %}Deprecated since version {deprecated}, will be removed in version {removed}{% endtrans %}
{% trans %}Deprecated since version {deprecated}, removed in version {removed}{% endtrans %}
+
+
+In docsbuild-scripts, when rewriting indexsidebar.html with actual versions:
+
+{% trans %}in development{% endtrans %}
+{% trans %}pre-release{% endtrans %}
+{% trans %}stable{% endtrans %}
+{% trans %}security-fixes{% endtrans %}
+{% trans %}EOL{% endtrans %}
diff --git a/Doc/tools/templates/indexsidebar.html b/Doc/tools/templates/indexsidebar.html
index 1c1cb54..f7bf6d8 100644
--- a/Doc/tools/templates/indexsidebar.html
+++ b/Doc/tools/templates/indexsidebar.html
@@ -2,12 +2,8 @@
<p><a href="{{ pathto('download') }}">{% trans %}Download these documents{% endtrans %}</a></p>
<h3>{% trans %}Docs by version{% endtrans %}</h3>
<ul>
- <li><a href="https://docs.python.org/3.10/">{% trans %}Python 3.10 (in development){% endtrans %}</a></li>
- <li><a href="https://docs.python.org/3.9/">{% trans %}Python 3.9 (pre-release){% endtrans %}</a></li>
- <li><a href="https://docs.python.org/3.8/">{% trans %}Python 3.8 (stable){% endtrans %}</a></li>
- <li><a href="https://docs.python.org/3.7/">{% trans %}Python 3.7 (stable){% endtrans %}</a></li>
- <li><a href="https://docs.python.org/3.6/">{% trans %}Python 3.6 (security-fixes){% endtrans %}</a></li>
- <li><a href="https://docs.python.org/2.7/">{% trans %}Python 2.7 (EOL){% endtrans %}</a></li>
+ <li><a href="https://docs.python.org/">{% trans %}Stable{% endtrans %}</a></li>
+ <li><a href="https://docs.python.org/dev/">{% trans %}In development{% endtrans %}</a></li>
<li><a href="https://www.python.org/doc/versions/">{% trans %}All versions{% endtrans %}</a></li>
</ul>
diff --git a/Doc/tools/templates/layout.html b/Doc/tools/templates/layout.html
index 17592d7..98ccf42 100644
--- a/Doc/tools/templates/layout.html
+++ b/Doc/tools/templates/layout.html
@@ -12,22 +12,14 @@
{% block rootrellink %}
{{ super() }}
- <li>
- {%- if switchers is defined %}
- <span class="language_switcher_placeholder">{{ language or 'en' }}</span>
- <span class="version_switcher_placeholder">{{ release }}</span>
- <a href="{{ pathto('index') }}">{% trans %}Documentation {% endtrans %}</a>{{ reldelim1 }}
- {%- else %}
+ <li id="cpython-language-and-version">
<a href="{{ pathto('index') }}">{{ shorttitle }}</a>{{ reldelim1 }}
- {%- endif %}
</li>
{% endblock %}
{% block extrahead %}
<link rel="canonical" href="https://docs.python.org/3/{{pagename}}.html" />
{% if builder != "htmlhelp" %}
- {% if switchers is defined and not embedded %}
- <script type="text/javascript" src="{{ pathto('_static/switchers.js', 1) }}"></script>{% endif %}
{% if pagename == 'whatsnew/changelog' and not embedded %}
<script type="text/javascript" src="{{ pathto('_static/changelog_search.js', 1) }}"></script>{% endif %}
{% endif %}