Skip to content

Commit

Permalink
allow disabling version banner
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Oct 24, 2024
1 parent ebf9ad2 commit 338bc4b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Unreleased

- When getting the canonical URL on Read the Docs, replace the path with
``/en/stable/`` instead of ``/page/``. This can be configured with
``rtd_canonical_path``. :pr:`119`
``rtd_canonical_path``. :pr:`122`
- The version banner can be disabled by setting ``version_banner = False``.
On Read the Docs, it is disabled when building the ``stable`` version or
PRs. :pr:`123`


Version 2.2.0
Expand Down
30 changes: 20 additions & 10 deletions src/pallets_sphinx_themes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setup(app):

app.add_config_value("is_pallets_theme", None, "html")
app.add_config_value("rtd_canonical_path", "/en/stable/", "html")
app.add_config_value("version_banner", True, "html")

# Use the sphinx-notfound-page extension to generate a 404 page with valid
# URLs. Only configure it if it's not already configured.
Expand Down Expand Up @@ -82,16 +83,25 @@ def find_base_canonical_url(app: Sphinx) -> None:

@only_pallets_theme()
def add_theme_files(app: Sphinx) -> None:
# Add the JavaScript for the version warning banner. Include the project and
# version as data attributes that the script will access. The project name
# is assumed to be the PyPI name, and is normalized to avoid a redirect.
app.add_js_file(
"describe_version.js",
**{
"data-project": re.sub(r"[-_.]+", "-", app.config.project).lower(),
"data-version": app.config.version,
},
)
# Add the JavaScript for the version warning banner if ``version_banner`` is
# enabled. On Read the Docs, don't include it for stable or PR builds.
# Include the project and version as data attributes that the script will
# access. The project name is assumed to be the PyPI name, and is normalized
# to avoid a redirect.
rtd_version = os.environ.get("READTHEDOCS_VERSION")
rtd_version_type = os.environ.get("READTHEDOCS_VERSION_TYPE")

if app.config.version_banner and (
rtd_version is None # not on read the docs
or (rtd_version != "stable" and rtd_version_type in {"branch", "tag"})
):
app.add_js_file(
"describe_version.js",
**{
"data-project": re.sub(r"[-_.]+", "-", app.config.project).lower(),
"data-version": app.config.version,
},
)


@only_pallets_theme()
Expand Down

0 comments on commit 338bc4b

Please sign in to comment.