Skip to content

Commit b34b188

Browse files
committed
docs: version the screenshot URLs so the CDN cannot serve a stale 404
The pages went live a few minutes before the deploy that added docs/resources, and the CDN cached the 404 for each screenshot a browser asked for in between, for four hours. Stamp every screenshot URL in the docs pages with a hash of the file, as the build already does for CSS and JS, so a new or late image is always a new URL. Signed-off-by: ravindu644 <droidcasts@protonmail.com>
1 parent 0ef17c0 commit b34b188

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎.github/scripts/build-docs.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ def ver(path):
450450
html = open(page).read()
451451
stamped = re.sub(r'(/assets/(?:css|js)/[\w.-]+)(?:\?v=\w+)?"',
452452
lambda m: f'{m.group(1)}?v={ver(os.path.join(root, m.group(1).lstrip("/")))}"', html)
453+
# the screenshots in the docs pages sit at docs/resources/ and are cached by the CDN the
454+
# same way, including a 404 fetched before the first deploy that added them
455+
stamped = re.sub(r'(src="resources/[\w./-]+)(?:\?v=\w+)?"',
456+
lambda m: f'{m.group(1)}?v={ver(os.path.join(root, "docs", m.group(1)[5:]))}"'
457+
if os.path.exists(os.path.join(root, "docs", m.group(1)[5:])) else m.group(0), stamped)
453458
if stamped != html:
454459
open(page, 'w').write(stamped)
455460
print("OK: asset versions")

0 commit comments

Comments
 (0)