diff --git a/docs/conf.py b/docs/conf.py index 14f8a0b19..2b8b9278e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,8 +46,25 @@ # -- Options for HTML output ------------------------------------------------- # Define the json_url for our version switcher. -json_url = "http://pybop-docs.readthedocs.io/en/latest/_static/switcher.json" +json_url = "https://pybop-docs.readthedocs.io/en/latest/_static/switcher.json" version_match = os.environ.get("READTHEDOCS_VERSION") +release = f"v{__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 it's "latest" → change to "dev" (that's what we want the switcher to call it) +# Credit: PyData Theme: https://github.com/pydata/pydata-sphinx-theme/blob/main/docs/conf.py +if not version_match or version_match.isdigit() or version_match == "latest": + # For local development, infer the version to match from the package. + if "latest" 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 +elif version_match == "stable": + version_match = release html_theme = "pydata_sphinx_theme" html_show_sourcelink = False @@ -72,7 +89,7 @@ "show_prev_next": False, "navbar_align": "content", "navbar_center": ["navbar-nav", "version-switcher"], - "show_version_warning_banner": True, + # "show_version_warning_banner": True, # Commented until we have a stable release with docs "footer_start": ["copyright"], "footer_center": ["sphinx-version"], "switcher": {