Skip to content

Commit f04b23c

Browse files
hugovkCAM-Gerlach
andauthored
Append a hash ?digest to CSS files for cache-busting (#1054)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 80cd894 commit f04b23c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

conf.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import hashlib
12
import os
23
import sys
34
import time
5+
from pathlib import Path
46

57
# Location of custom extensions.
68
sys.path.insert(0, os.path.abspath(".") + "/_extensions")
@@ -32,14 +34,22 @@
3234
'.github',
3335
]
3436

37+
def _asset_hash(path: os.PathLike[str]) -> str:
38+
"""Append a `?digest=` to an url based on the file content."""
39+
full_path = (Path(html_static_path[0]) / path).resolve()
40+
digest = hashlib.sha1(full_path.read_bytes()).hexdigest()
41+
42+
return f"{path}?digest={digest}"
43+
44+
3545
html_theme = 'furo'
3646
html_theme_options = {
3747
"source_repository": "https://github.com/python/devguide",
3848
"source_branch": "main",
3949
}
4050
html_static_path = ['_static']
4151
html_css_files = [
42-
'devguide_overrides.css',
52+
_asset_hash('devguide_overrides.css'),
4353
]
4454
html_logo = "_static/python-logo.svg"
4555
html_favicon = "_static/favicon.png"

0 commit comments

Comments
 (0)