Skip to content

Commit 338bc4b

Browse files
committed
allow disabling version banner
1 parent ebf9ad2 commit 338bc4b

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

CHANGES.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ Unreleased
55

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

1013

1114
Version 2.2.0

src/pallets_sphinx_themes/__init__.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def setup(app):
2626

2727
app.add_config_value("is_pallets_theme", None, "html")
2828
app.add_config_value("rtd_canonical_path", "/en/stable/", "html")
29+
app.add_config_value("version_banner", True, "html")
2930

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

8384
@only_pallets_theme()
8485
def add_theme_files(app: Sphinx) -> None:
85-
# Add the JavaScript for the version warning banner. Include the project and
86-
# version as data attributes that the script will access. The project name
87-
# is assumed to be the PyPI name, and is normalized to avoid a redirect.
88-
app.add_js_file(
89-
"describe_version.js",
90-
**{
91-
"data-project": re.sub(r"[-_.]+", "-", app.config.project).lower(),
92-
"data-version": app.config.version,
93-
},
94-
)
86+
# Add the JavaScript for the version warning banner if ``version_banner`` is
87+
# enabled. On Read the Docs, don't include it for stable or PR builds.
88+
# Include the project and version as data attributes that the script will
89+
# access. The project name is assumed to be the PyPI name, and is normalized
90+
# to avoid a redirect.
91+
rtd_version = os.environ.get("READTHEDOCS_VERSION")
92+
rtd_version_type = os.environ.get("READTHEDOCS_VERSION_TYPE")
93+
94+
if app.config.version_banner and (
95+
rtd_version is None # not on read the docs
96+
or (rtd_version != "stable" and rtd_version_type in {"branch", "tag"})
97+
):
98+
app.add_js_file(
99+
"describe_version.js",
100+
**{
101+
"data-project": re.sub(r"[-_.]+", "-", app.config.project).lower(),
102+
"data-version": app.config.version,
103+
},
104+
)
95105

96106

97107
@only_pallets_theme()

0 commit comments

Comments
 (0)