From c782ba0303356013abd88680ccdf386b502234f1 Mon Sep 17 00:00:00 2001 From: Anno Knierim Date: Wed, 19 Jul 2023 14:17:23 +0200 Subject: [PATCH] Add navbar version switcher --- docs/_static/switcher.json | 72 ++++++++++++++++++++++++++++++++++++++ docs/conf.py | 28 +++++++++++++-- 2 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 docs/_static/switcher.json diff --git a/docs/_static/switcher.json b/docs/_static/switcher.json new file mode 100644 index 00000000000..59a6b3a5637 --- /dev/null +++ b/docs/_static/switcher.json @@ -0,0 +1,72 @@ +[ + { + "name": "dev", + "version": "latest", + "url": "https://ctapipe.readthedocs.io/en/latest/" + }, + { + "name": "v0.19.2 (stable)", + "version": "stable", + "url": "https://ctapipe.readthedocs.io/en/stable/" + }, + { + "name": "v0.19.3", + "version": "v0.19.3", + "url": "https://ctapipe.readthedocs.io/en/v0.19.3/" + }, + { + "name": "v0.19.2", + "version": "v0.19.2", + "url": "https://ctapipe.readthedocs.io/en/v0.19.2/" + }, + { + "name": "v0.19.1", + "version": "v0.19.1", + "url": "https://ctapipe.readthedocs.io/en/v0.19.1/" + }, + { + "name": "v0.19.0", + "version": "v0.19.0", + "url": "https://ctapipe.readthedocs.io/en/v0.19.0/" + }, + { + "name": "v0.18.1", + "version": "v0.18.1", + "url": "https://ctapipe.readthedocs.io/en/v0.18.1/" + }, + { + "name": "v0.18.0", + "version": "v0.18.0", + "url": "https://ctapipe.readthedocs.io/en/v0.18.0/" + }, + { + "name": "v0.17.0", + "version": "v0.17.0", + "url": "https://ctapipe.readthedocs.io/en/v0.17.0/" + }, + { + "name": "v0.16.0", + "version": "v0.16.0", + "url": "https://ctapipe.readthedocs.io/en/v0.16.0/" + }, + { + "name": "v0.15.0", + "version": "v0.15.0", + "url": "https://ctapipe.readthedocs.io/en/v0.15.0/" + }, + { + "name": "v0.14.0", + "version": "v0.14.0", + "url": "https://ctapipe.readthedocs.io/en/v0.14.0/" + }, + { + "name": "v0.12.0-rtd", + "version": "v0.12.0-rtd", + "url": "https://ctapipe.readthedocs.io/en/v0.12.0-rtd/" + }, + { + "name": "v0.11.0-rtd", + "version": "v0.11.0-rtd", + "url": "https://ctapipe.readthedocs.io/en/v0.11.0-rtd/" + } +] diff --git a/docs/conf.py b/docs/conf.py index 3c493c6920d..4c228dc4886 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -190,6 +190,26 @@ def setup(app): todo_include_todos = True +# -- Version switcher ----------------------------------------------------- + +# Define the json_url for our version switcher. +json_url = "https://ctapipe.readthedocs.io/en/latest/_static/switcher.json" + +# Define the version we use for matching in the version switcher. +version_match = os.environ.get("READTHEDOCS_VERSION") +# If READTHEDOCS_VERSION doesn't exist, we're not on RTD +# If it is an integer, we're in a PR build and the version isn't correct. +if not version_match or version_match.isdigit(): + # For local development, infer the version to match from the package. + if "dev" in release or "rc" in release: + version_match = "latest" + # We want to keep the relative reference if we are in dev mode + # but we want the whole url if we are effectively in a released version + json_url = "_static/switcher.json" + else: + version_match = release + + # -- Options for HTML output ---------------------------------------------- html_theme = "pydata_sphinx_theme" @@ -208,7 +228,11 @@ def setup(app): }, "github_url": "https://github.com/cta-observatory/ctapipe", "header_links_before_dropdown": 6, - "navbar_start": ["navbar-logo"], + "navbar_start": ["navbar-logo", "version-switcher"], + "switcher": { + "version_match": version_match, + "json_url": json_url, + }, "use_edit_page_button": True, "icon_links_label": "Quick Links", "icon_links": [ @@ -226,8 +250,6 @@ def setup(app): """, } -html_sidebars = {"**": ["sidebar-nav-bs.html", "sidebar-ethical-ads.html"]} - # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css".