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 @@ - + \ No newline at end of file diff --git a/connect/index.html b/connect/index.html index 92e0625..dcf964b 100644 --- a/connect/index.html +++ b/connect/index.html @@ -13,7 +13,7 @@ - + @@ -197,7 +197,7 @@ - + \ No newline at end of file diff --git a/festivals/index.html b/festivals/index.html index a624d07..3fe2a06 100644 --- a/festivals/index.html +++ b/festivals/index.html @@ -13,7 +13,7 @@ - + @@ -248,7 +248,7 @@ - + \ No newline at end of file diff --git a/index.html b/index.html index 10344a1..03337da 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@ - + @@ -277,7 +277,7 @@ - + \ No newline at end of file diff --git a/schedule/index.html b/schedule/index.html index 48e9832..ad6df05 100644 --- a/schedule/index.html +++ b/schedule/index.html @@ -13,7 +13,7 @@ - + @@ -124,7 +124,7 @@ - + + \ No newline at end of file