From 074f21fde3ca29644ac6c0a6a94fa37508d16d81 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 21 May 2024 02:15:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Remove=20duplicate=20CSS=20hashi?= =?UTF-8?q?ng=20for=20sphinx=20>=3D=207.1=20(#193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since sphinx v7.1, a checksum is already added to the CSS file URL, so hashing the content is no longer necessary (see https://github.com/sphinx-doc/sphinx/pull/11415) --- sphinx_design/extension.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sphinx_design/extension.py b/sphinx_design/extension.py index 607e39a..21ec03d 100644 --- a/sphinx_design/extension.py +++ b/sphinx_design/extension.py @@ -3,6 +3,7 @@ from docutils import nodes from docutils.parsers.rst import directives +from sphinx import version_info as sphinx_version from sphinx.application import Sphinx from sphinx.environment import BuildEnvironment from sphinx.transforms import SphinxTransform @@ -67,9 +68,14 @@ def update_css_js(app: Sphinx): js_path.write_text(content) # Read the css content and hash it content = read_text(static_module, "style.min.css") - hash = hashlib.md5(content.encode("utf8")).hexdigest() # Write the css file - css_path = static_path / f"design-style.{hash}.min.css" + if sphinx_version < (7, 1): + hash = hashlib.md5(content.encode("utf8")).hexdigest() + css_path = static_path / f"sphinx-design.{hash}.min.css" + else: + # since sphinx 7.1 a checksum is added to the css file URL, so there is no need to do it here + # https://github.com/sphinx-doc/sphinx/pull/11415 + css_path = static_path / "sphinx-design.min.css" app.add_css_file(css_path.name) if css_path.exists(): return