diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..7516756 --- /dev/null +++ b/.githooks/pre-commit @@ -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" diff --git a/classes/index.html b/classes/index.html index b09f065..fcbc78a 100644 --- a/classes/index.html +++ b/classes/index.html @@ -13,7 +13,7 @@ - +
@@ -379,7 +379,7 @@ - +