Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35291f8

Browse files
committed
Reorder URLs to put optional <target> element at the end
Makes a lot of things simpler
1 parent 0421416 commit 35291f8

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ var DOCUMENTATION_VERSIONS = {
6464
};
6565
```
6666

67-
.. note:: This file is JavaScript so it can be easily included in a script tag, but it's excpected to contain a single assignment statement which assigns the ``DOCUMENTATION_VERSIONS`` variable to a valid JSON object. Doing any other JavaScript computation in this file is invalid.
67+
.. note:: This file is JavaScript so it can be easily included in a script tag, but it's expected to contain a single assignment statement which assigns the ``DOCUMENTATION_VERSIONS`` variable to a valid JSON object. Doing any other JavaScript computation in this file is invalid.
6868

6969
Inside the ``DOCUMENTATION_VERSIONS`` object:
7070

7171
- ``VERSIONS`` key is a list of versions, where each version is a JSON object with at minimum a ``name`` key which is the version name "slug", and optionally one or more of the following keys:
72-
- ``has_targets`` is true if the URLs for these docs have a target element, ie ``<project>/<language>/<target>/<version>``. False if the URL format is ``<project>/<language>/<version>``. A single project can have some versions which include and some which exclude the target URL component.
72+
- ``has_targets`` is true if the URLs for these docs have a target element, ie ``<project>/<language>/<version>/<target>``. False if the URL format is ``<project>/<language>/<version>``. A single project can have some versions which include and some which exclude the target URL component, and the theme will try to generate version links that add or drop the ``<target>`` element as applicable.
7373
- ``old`` is true if this version is not current, will be shown in "Old Versions" section under the main versions.
7474
- ``pre_release`` is true if this version is a prerelease not a stable release, will be shown in "Prereleases" section under the main versions
75-
- ``DEFAULTS`` key contains the default values for any keys which are not supplied in an individual ``VERSIONS`` entries. Just exists to make the file more readable.
75+
- ``DEFAULTS`` key contains the default values for any keys which are not supplied in an individual version object. This exists as "sugar" to make the file more readable.
7676

7777

7878

sphinx_idf_theme/versions.html

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
{% if idf_targets %}
1010
<dl>
1111
<dt>{{ _('Targets') }}</dt>
12-
{% for slug in idf_targets %}
13-
{% if slug == idf_target %}
12+
{% for target in idf_targets %}
13+
{% if target == idf_target %}
1414
<strong>
1515
{% endif %}
16-
<dd><a href="{{ pathto('../..', 1) }}/{{ slug }}/{{ version }}/{{ pagename }}.html">{{ slug }}</a></dd>
17-
{% if slug == idf_target %}
16+
<dd><a href="{{ pathto('../..', 1) }}/{{ release }}/{{ target }}/{{ pagename }}.html">{{ target }}</a></dd>
17+
{% if target == idf_target %}
1818
</strong>
1919
{% endif %}
2020
{% endfor %}
@@ -23,16 +23,16 @@
2323
{% if languages %}
2424
<dl>
2525
<dt>{{ _('Languages') }}</dt>
26-
{% for slug in languages %}
27-
{% if slug == language %}
26+
{% for language in languages %}
27+
{% if language == language %}
2828
<strong>
2929
{% endif %}
3030
{% if idf_targets %}
31-
<dd><a href="{{ pathto('../../..', 1) }}/{{ slug }}/{{ idf_target }}/{{ version }}/{{ pagename }}.html">{{ slug }}</a></dd>
31+
<dd><a href="{{ pathto('../../..', 1) }}/{{ language }}/{{ release }}/{{ idf_target }}/{{ pagename }}.html">{{ language }}</a></dd>
3232
{% else %}
33-
<dd><a href="{{ pathto('../..', 1) }}/{{ slug }}/{{ version }}/{{ pagename }}.html">{{ slug }}</a></dd>
33+
<dd><a href="{{ pathto('../..', 1) }}/{{ language }}/{{ release }}/{{ pagename }}.html">{{ language }}</a></dd>
3434
{% endif %}
35-
{% if slug == language %}
35+
{% if language == language %}
3636
</strong>
3737
{% endif %}
3838
{% endfor %}
@@ -45,14 +45,22 @@
4545
{% endif %}
4646
<!-- Latest version URL may not be correct depending on whether that version has idf_target as part of the URL format compared to this version.
4747
JavaScript will update it on page load -->
48+
{% if idf_targets %}
49+
<dd id="version-latest"><a href="{{ pathto('../..', 1) }}/latest/{{ idf_target }}/{{ pagename }}.html">latest</a></dd>
50+
{% else %}
4851
<dd id="version-latest"><a href="{{ pathto('..', 1) }}/latest/{{ pagename }}.html">latest</a></dd>
52+
{% endif %}
4953
{% if release == "latest" %}
5054
</strong>
5155
{% endif %}
5256

5357
<!-- Stable version URL may not be correct depending on whether that version has idf_target as part of the URL format compared to this version.
5458
JavaScript will update it on page load -->
59+
{% if idf_targets %}
60+
<dd id="version-stable"><a href="{{ pathto('../..', 1) }}/stable/{{ idf_target }}/{{ pagename }}.html">stable</a></dd>
61+
{% else %}
5562
<dd id="version-stable"><a href="{{ pathto('..', 1) }}/stable/{{ pagename }}.html">stable</a></dd>
63+
{% endif %}
5664
</dl>
5765
<dl id="versions-prerelease">
5866
<dt hidden>{{ _('Prereleases') }}</dt>

src/idf_embeds.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function setupVersions() {
2424
}
2525

2626
/* Find the (relative) base URL for this project, finding a sibling URL will be built as follows:
27-
<project_base_url>/<language>/<idf_target>/<version>
27+
<project_base_url>/<language>/<version>/<idf_target>
2828
2929
(Where 'idf_target' path element are optional depending on if the project has multiple target support)
3030
*/
@@ -36,11 +36,10 @@ function setupVersions() {
3636

3737
/* Given a version from the list, return the URL to link to it */
3838
function getVersionUrl(v) {
39-
let result = project_base_url + "/" + language;
39+
let result = project_base_url + "/" + language + "/" + v.name;
4040
if (v.has_targets) {
4141
result += "/" + (idf_target || "esp32");
4242
}
43-
result += "/" + v.name;
4443

4544
result += "/" + pagename; // add the relative path of this page
4645

0 commit comments

Comments
 (0)