fix: cache canonical GTIN page without redirects

This commit is contained in:
desfoto automation
2026-09-25 20:02:16 +02:00
parent 8be63309d3
commit de6de3c6c4
4 changed files with 35 additions and 15 deletions

View File

@@ -14,6 +14,7 @@ from __future__ import annotations
import base64
import datetime as dt
import hashlib
import io
import json
import shutil
@@ -285,6 +286,7 @@ def build_html(table: dict[str, dict]) -> list[tuple[str, str]]:
print(f" [html] {rel}")
shutil.rmtree(SITE / "gtin", ignore_errors=True)
shutil.copytree(SRC / "gtin", SITE / "gtin")
version_gtin_service_worker()
print(" [html] gtin/ (unlisted browser tool and standalone legal pages)")
not_found = pages.not_found().replace("og-desfoto.jpg", "og-desfoto.jpg")
(SITE / "404.html").write_text(not_found, encoding="utf-8")
@@ -292,6 +294,26 @@ def build_html(table: dict[str, dict]) -> list[tuple[str, str]]:
return written
def version_gtin_service_worker() -> None:
"""Give each GTIN source release its own offline cache."""
digest = hashlib.sha256()
source_root = SRC / "gtin"
for path in sorted(source_root.rglob("*")):
if not path.is_file():
continue
digest.update(path.relative_to(source_root).as_posix().encode("utf-8"))
digest.update(b"\0")
digest.update(path.read_bytes())
digest.update(b"\0")
worker = SITE / "gtin" / "sw.js"
script = worker.read_text(encoding="utf-8")
marker = "__BUILD_VERSION__"
if script.count(marker) != 1:
raise RuntimeError("GTIN service worker cache version marker is missing or duplicated")
worker.write_text(script.replace(marker, digest.hexdigest()[:12]), encoding="utf-8")
def build_meta_files(routes: list[tuple[str, str]]) -> None:
today = dt.date.today().isoformat()
urls = []