Skip to content

Commit

Permalink
👌 Remove duplicate CSS hashing for sphinx >= 7.1 (#193)
Browse files Browse the repository at this point in the history
Since sphinx v7.1, a checksum is already added to the CSS file URL, so hashing the content is no longer necessary (see sphinx-doc/sphinx#11415)
  • Loading branch information
chrisjsewell authored May 21, 2024
1 parent be1b85d commit 074f21f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sphinx_design/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 074f21f

Please sign in to comment.