IDF theme for Sphinx, based on Read The Docs theme
Project description
This is a fork of sphinx-rtd-theme by Read The Docs. This fork is used by the ESP-IDF Programming Guide. Espressif forked this theme when we moved ESP-IDF Programming Guide away from Read The Docs’ hosted service and needed some functionality that neither RTD nor the theme provide out of the box.
Notes for ESP-IDF Theme
Development Builds
This theme must be imported as a Python package not using Sphinx’s html_theme_path option, as it relies on some code in __init__.py. The sphinx_idf_theme needs a mixture of Python and JavaScript in order to build. So currently it’s necessary install node.js in order to build it locally. To debug the theme in development, setup.py develop doesn’t seem to work out of the box (can probably be made to work easily, please update this file if you know the steps). The following hacky approach definitely works:
Run npm install in this directory.
Run python3 setup.py build in this directory.
In top of IDF docs conf_common.py, add a temporary sys.path.append('/path/to/here/build/lib').
Remove sphinx_idf_theme==0.X from doc/requirement.txt
Run IDF docs build, it will import the just-built theme from this directory as a package.
(When changing theme, re-run setup.py build).
New Features
Can support a new URL component under the RTD project/language/version URL standard, so projects can be project/language/version/target if the project has multiple targets which each have a totally different docs build.
Loads the version information in the versions popup using JavaScript on the client (see “Versions file” below). No dynamic webserver support is needed but the popup can be updated without needing to rebuild all versions of the docs.
Technical Changes
New JavaScript file idf_embeds.js is compiled into theme.js, sets up version footer.
Templates for layout & versions.html have been modified.
To Use In a Sphinx Project
Set the following additional config variables in the Sphinx project:
idf_target - slug of the IDF target (ie esp32, esp32s2). Optional, but either both this option and idf_targets must be set or neither must be set.
idf_targets - Python list with short names of all supported IDF targets (ie ["esp32", "esp32s2"]).
idf_target_title_dict - Python dictonary which maps from short names of all supported IDF targets (ie ["esp32", "esp32s2"]) to full names (ie ["ESP32", "ESP32-S2"]).
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)
project_slug - short name of the project as a URL slug (ie esp-idf)
versions_url - URL to download the versions.js file from
project_homepage - URL of the project’s main page (GitHub, etc)
pdf_file - Optional, URL to the page where the PDF of HTML is stored, relative to the root dir, used for generating the link to download the PDF
version - Standard Sphinx variable, holds the comprehensive version number of the project.
release - This should be the “human readable” version of the version. release is used in URL slugs, and is used to pattern match inside the Versions file. Currently in ESP-IDF docs, release is generated using similar sanitization rules to RTD (summary: uses the tag name if available, or branch name if available, or falls back to version otherwise. master becomes latest, any branch name with a / in it becomes a -.)
Versions file
The file found at the versions_url location should be a JavaScript file describing all current versions. It is loaded by JavaScript in the theme and used to build the target and version switching selector.
The file should take this form:
var DOCUMENTATION_VERSIONS = {
"DEFAULTS": { "has_targets": false, supported_targets: [] },
"VERSIONS": [
{ "name": "latest", "has_targets": true, supported_targets: [ "esp32", "esp32s2", "esp32s3" ] },
{ "name": "v4.0" },
{ "name": "v3.3.1" },
{ "name": "v3.3", "old": true },
{ "name": "v3.2.3" },
{ "name": "v3.2.2", "old": true },
{ "name": "v3.1.6" },
{ "name": "v3.1.5", "old": true },
{ "name": "v3.0.9", "old": true },
{ "name": "v4.0-rc", "pre_release": true },
{ "name": "v4.0-beta2", "pre_release": true },
{ "name": "release-v4.1", "pre_release": true },
{ "name": "release-v4.0", "pre_release": true },
{ "name": "release-v3.3", "pre_release": true },
{ "name": "release-v3.2", "pre_release": true },
{ "name": "release-v3.1", "pre_release": true },
]
};
Inside the DOCUMENTATION_VERSIONS object:
VERSIONS key is a list of versions
Each version is a JSON object with at minimum a name key which is the version name “slug” (corresponds to release config variable).
Optionally, one or more of the following keys: - 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. - old is true if this version is not current, will be shown in “Old Versions” section under the main versions. - pre_release is true if this version is a prerelease not a stable release, will be shown in “Prereleases” section under the main versions - supported_targets list of supported targets used for generating the target selector for this specific version.
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.
Original RTD Theme README
This Sphinx theme was designed to provide a great reader experience for documentation users on both desktop and mobile devices. This theme is used primarily on Read the Docs but can work with any Sphinx project. You can find a working demo of the theme in the theme documentation
Installation
This theme is distributed on PyPI and can be installed with pip:
$ pip install sphinx-idf-theme
To use the theme in your Sphinx project, you will need to add the following to your conf.py file:
import sphinx_idf_theme
extensions = [
...
"sphinx_idf_theme",
]
html_theme = "sphinx_idf_theme"
For more information read the full documentation on installing the theme
Configuration
This theme is highly customizable on both the page level and on a global level. To see all the possible configuration options, read the documentation on configuring the theme.
Contributing
If you would like to help modify or translate the theme, you’ll find more information on contributing in our contributing guide.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sphinx_idf_theme-0.4.0.tar.gz
.
File metadata
- Download URL: sphinx_idf_theme-0.4.0.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a3046aa5fc275a621e0140e4c274ab17164d6ca1a95f2c4971c11c3579222c1 |
|
MD5 | 24b3d650c7b29f49e51026c2a712e35d |
|
BLAKE2b-256 | 4122f6be130ef91af015cf23b36dd584a3daffc71fd8c8bc1cb769db84f6f751 |
File details
Details for the file sphinx_idf_theme-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: sphinx_idf_theme-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 2.8 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6db05d07ed74a2935c89ed6240d12d42f21bfebb81aeec4667b8c1a0b18dcfe7 |
|
MD5 | fa8f312fd9eaf46a1b750fe4cca7b6f0 |
|
BLAKE2b-256 | 5eb4068ae0b11a4629fa86dfc433966c8152f4b31e24e390b530d91fa87a7f94 |