Skip to main content

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_assets 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, if specified as a relative URL (starts with ./) then it will be downloaded relative to the HTML root folder.

  • 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.

The order of the releases determines the order they show up in the version selector as well as the priority order when linking to different targets (if currently selected version do not support the target). Thus the order should ideally be sorted, with newer releases being listed first.

Original RTD Theme README

Pypi Version Build Status License Documentation Status

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 edit your conf.py file’s html_theme setting:

html_theme = "sphinx_idf_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_idf_theme-1.0.0.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

sphinx_idf_theme-1.0.0-py2.py3-none-any.whl (2.8 MB view details)

Uploaded Python 2 Python 3

File details

Details for the file sphinx_idf_theme-1.0.0.tar.gz.

File metadata

  • Download URL: sphinx_idf_theme-1.0.0.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.10

File hashes

Hashes for sphinx_idf_theme-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ef1fa6b1a75c5ac4100f396a2740b7497812272d63c2d3b22281ab518b4c7e3f
MD5 c4b68e8d16bcff549880e91f28ea038f
BLAKE2b-256 b74200b4ab3a59fb6627f54932c49961ad4d81fe537feaea5db4faba42ac571d

See more details on using hashes here.

File details

Details for the file sphinx_idf_theme-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_idf_theme-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7a806a19b07de4b3ba2c446693c14827da24e4993697a20f9e40e99055f61765
MD5 7898a85bf3b00b97e5c15ce14bd7a7b4
BLAKE2b-256 4187d0336a9caeaf81e3a142866140f55aa9dbbc6c33520956c101e923bb5bb7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page