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

Skip to content

Commit 0421416

Browse files
committed
Make 'versions' element mandatory
1 parent 7aaa6bd commit 0421416

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

README.rst

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,51 @@ Set the following additional config variables in the Sphinx project:
2828

2929
- ``idf_target`` - slug of the IDF target (ie esp32, esp32s2). Optional, but if ``idf_target`` is set then ``idf_targets`` must be set and vice versa. If these two are unset, no "Targets" section is generated in the navigation footer.
3030
- ``idf_targets`` - Python list with short names of all supported IDF targets (ie ``["esp32", "esp32s2"]``).
31-
- ``languages`` - Python list with short names of all supported languages (ie ``["en", "zh_CN"]``). If this is unset, no "Languages" section is generated in then navigation footer.
31+
- ``languages`` - Python list with short names of all supported languages (ie ``["en", "zh_CN"]``). Must be set to at least one language element (the current project's language)
3232
- ``project_slug`` - short name of the project as a URL slug (ie ``esp-idf``)
3333
- ``versions_url`` - URL to download the ``versions.js`` file from
3434
- ``project_homepage`` - URL of the project's main page (GitHub, etc)
3535

3636
Versions file
3737
^^^^^^^^^^^^^
3838

39-
TBD
39+
The file found at the ``versions_url`` location should be a JavaScript file describing all current versions. It should take this form:
40+
41+
.. highlight:: javascript
42+
43+
```
44+
var DOCUMENTATION_VERSIONS = {
45+
"DEFAULTS": { "has_targets": false },
46+
"VERSIONS": [
47+
{ "name": "latest", "has_targets": true },
48+
{ "name": "v4.0" },
49+
{ "name": "v3.3.1" },
50+
{ "name": "v3.3", "old": true },
51+
{ "name": "v3.2.3" },
52+
{ "name": "v3.2.2", "old": true },
53+
{ "name": "v3.1.6" },
54+
{ "name": "v3.1.5", "old": true },
55+
{ "name": "v3.0.9", "old": true },
56+
{ "name": "v4.0-rc", "pre_release": true },
57+
{ "name": "v4.0-beta2", "pre_release": true },
58+
{ "name": "release-v4.1", "pre_release": true },
59+
{ "name": "release-v4.0", "pre_release": true },
60+
{ "name": "release-v3.3", "pre_release": true },
61+
{ "name": "release-v3.2", "pre_release": true },
62+
{ "name": "release-v3.1", "pre_release": true },
63+
]
64+
};
65+
```
66+
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.
68+
69+
Inside the ``DOCUMENTATION_VERSIONS`` object:
70+
71+
- ``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.
73+
- ``old`` is true if this version is not current, will be shown in "Old Versions" section under the main versions.
74+
- ``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.
4076

4177

4278

sphinx_idf_theme/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setup(app):
2929
app.add_config_value('project_homepage', '', 'html')
3030
app.add_config_value('languages', None, 'html')
3131

32-
# we expect IDF to also add these, but older version may not
32+
# we expect IDF to also add these, but older version may not (and the theme supports non-target-aware docs)
3333
if "idf_target" not in app.config:
3434
app.add_config_value('idf_target', None, 'env')
3535
if "idf_targets" not in app.config:
@@ -46,5 +46,10 @@ def inject_template_context(app, pagename, templatename, context, doctree):
4646
# expose some IDF-specific config in the html_context dict for the theme
4747
for key in [ "project_slug", "versions_url", "project_homepage", "languages", "idf_target", "idf_targets", "project" ]:
4848
context[key] = app.config[key]
49+
50+
if not app.config.languages:
51+
raise RuntimeError("The 'languages' config item needs to be set to a list of supported languages (even if just a single element list)")
52+
if not app.config.language:
53+
raise RuntimeError("The 'language' config item needs to be set to the language in use")
4954
if bool(app.config.idf_target) != bool(app.config.idf_targets):
5055
raise RuntimeError("Either both 'idf_target' and 'idf_targets' variables should be set in Sphinx config, or neither should be set in config.")

sphinx_idf_theme/versions.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
{% if release == "latest" %}
4444
<strong>
4545
{% endif %}
46-
<!-- Latest version URL may not be correct depending on whether that version has different language & idf_targets as part of the URL format compared to this version.
46+
<!-- 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 -->
4848
<dd id="version-latest"><a href="{{ pathto('..', 1) }}/latest/{{ pagename }}.html">latest</a></dd>
4949
{% if release == "latest" %}
5050
</strong>
5151
{% endif %}
5252

53-
<!-- Stable version URL may not be correct depending on whether that version has different language & idf_targets as part of the URL format compared to this version.
53+
<!-- 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.
5454
JavaScript will update it on page load -->
5555
<dd id="version-stable"><a href="{{ pathto('..', 1) }}/stable/{{ pagename }}.html">stable</a></dd>
5656
</dl>

src/idf_embeds.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,17 @@ function setupVersions() {
2626
/* Find the (relative) base URL for this project, finding a sibling URL will be built as follows:
2727
<project_base_url>/<language>/<idf_target>/<version>
2828
29-
(Where language and target path elements are optional depending on if the project/version has these.)
29+
(Where 'idf_target' path element are optional depending on if the project has multiple target support)
3030
*/
31-
let project_base_url = DOCUMENTATION_OPTIONS.URL_ROOT + "..";
32-
if (DOCUMENTATION_OPTIONS.LANGUAGES) {
33-
project_base_url += "/..";
34-
}
31+
let project_base_url = DOCUMENTATION_OPTIONS.URL_ROOT + "../..";
3532
if (DOCUMENTATION_OPTIONS.IDF_TARGETS) {
3633
project_base_url += "/..";
3734
}
3835
console.log("project_base_url = " + project_base_url);
3936

4037
/* Given a version from the list, return the URL to link to it */
4138
function getVersionUrl(v) {
42-
let result = project_base_url;
43-
if (v.has_languages) {
44-
result += "/" + (language || "en");
45-
}
39+
let result = project_base_url + "/" + language;
4640
if (v.has_targets) {
4741
result += "/" + (idf_target || "esp32");
4842
}
@@ -58,7 +52,7 @@ function setupVersions() {
5852
/* Highlight the stable version if that's what we're looking at */
5953
$( "#version-stable>a" ).wrap("<strong></strong>");
6054
} else {
61-
/* Rewrite the URL for stable to account for languages/targets in that version */
55+
/* Rewrite the URL for stable to account for targets (or not) in that particular version */
6256
stable = jQuery.extend({}, stable); // clone the version object to make the name 'stable'
6357
stable.name = "stable";
6458
$( "#version-stable>a" ).attr("href", getVersionUrl(stable));

0 commit comments

Comments
 (0)