From 9e40071eb8c4c3e38845b57c4f5242bef2a44af2 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Fri, 1 Sep 2023 23:33:02 +0100 Subject: [PATCH] Make asset hash injection idempotent This makes things work correctly on Sphinx 6, while preserving compatibility with Sphinx 7. --- src/furo/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/furo/__init__.py b/src/furo/__init__.py index 95502670..17c2bfbc 100644 --- a/src/furo/__init__.py +++ b/src/furo/__init__.py @@ -163,7 +163,17 @@ def _add_asset_hashes(static: List[str], add_digest_to: List[str]) -> None: return for asset in add_digest_to: - index = static.index("_static/" + asset) + try: + index = static.index("_static/" + asset) + except ValueError: + raise ConfigError( + "Furo is trying to add a digest to an asset that is not in the " + f"static files: {asset}. Please check conf.py for overrides of " + "theme-provide assets such as `html_style`." + ) + + if "?digest=" in static[index].filename: # make this idempotent + continue static[index].filename = _asset_hash(asset) # type: ignore @@ -175,12 +185,6 @@ def _html_page_context( doctree: Any, ) -> None: if "css_files" in context: - if "_static/styles/furo.css" not in [c.filename for c in context["css_files"]]: - raise ConfigError( - "This documentation is not using `furo.css` as the stylesheet. " - "If you have set `html_style` in your conf.py file, remove it." - ) - _add_asset_hashes( context["css_files"], ["styles/furo.css", "styles/furo-extensions.css"],