Fix cache

This commit is contained in:
2026-05-02 12:38:58 +07:00
parent f7d44cb26a
commit ca3a5e8926
7 changed files with 31 additions and 12 deletions

19
.githooks/pre-commit Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# Cache-busting: update ?v= query param in all HTML files when CSS/JS change.
# Version = first 8 chars of a combined hash of style.css + main.js.
REPO_ROOT=$(git rev-parse --show-toplevel)
CSS="$REPO_ROOT/css/style.css"
JS="$REPO_ROOT/js/main.js"
VERSION=$(cat "$CSS" "$JS" | git hash-object --stdin | cut -c1-8)
HTML_FILES=$(find "$REPO_ROOT" -name "index.html" -not -path "*/raw/*")
for file in $HTML_FILES; do
sed -i -E "s|(\.\.\/)?css/style\.css(\?v=[^\"']*)?|\1css/style.css?v=$VERSION|g" "$file"
sed -i -E "s|(\.\.\/)?js/main\.js(\?v=[^\"']*)?|\1js/main.js?v=$VERSION|g" "$file"
git add "$file"
done
echo "Cache-bust version: $VERSION"