Fix cache
This commit is contained in:
19
.githooks/pre-commit
Normal file
19
.githooks/pre-commit
Normal 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"
|
||||
@@ -13,7 +13,7 @@
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..60,700;12..60,800&family=Caveat+Brush&family=JetBrains+Mono:wght@400;500&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap"
|
||||
rel="stylesheet">
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<link rel="stylesheet" href="../css/style.css?v=ba34a4ab">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -379,7 +379,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="../js/main.js"></script>
|
||||
<script src="../js/main.js?v=ba34a4ab"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -13,7 +13,7 @@
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..60,700;12..60,800&family=Caveat+Brush&family=JetBrains+Mono:wght@400;500&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap"
|
||||
rel="stylesheet">
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<link rel="stylesheet" href="../css/style.css?v=ba34a4ab">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -197,7 +197,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="../js/main.js"></script>
|
||||
<script src="../js/main.js?v=ba34a4ab"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -13,7 +13,7 @@
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..60,700;12..60,800&family=Caveat+Brush&family=JetBrains+Mono:wght@400;500&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap"
|
||||
rel="stylesheet">
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<link rel="stylesheet" href="../css/style.css?v=ba34a4ab">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -248,7 +248,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="../js/main.js"></script>
|
||||
<script src="../js/main.js?v=ba34a4ab"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -13,7 +13,7 @@
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..60,700;12..60,800&family=Caveat+Brush&family=JetBrains+Mono:wght@400;500&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap"
|
||||
rel="stylesheet">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<link rel="stylesheet" href="css/style.css?v=ba34a4ab">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -277,7 +277,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="js/main.js"></script>
|
||||
<script src="js/main.js?v=ba34a4ab"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -13,7 +13,7 @@
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..60,700;12..60,800&family=Caveat+Brush&family=JetBrains+Mono:wght@400;500&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap"
|
||||
rel="stylesheet">
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<link rel="stylesheet" href="../css/style.css?v=ba34a4ab">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -124,7 +124,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="../js/main.js"></script>
|
||||
<script src="../js/main.js?v=ba34a4ab"></script>
|
||||
<script>
|
||||
// Dynamic last-update label
|
||||
(function () {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..60,700;12..60,800&family=Caveat+Brush&family=JetBrains+Mono:wght@400;500&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap"
|
||||
rel="stylesheet">
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<link rel="stylesheet" href="../css/style.css?v=ba34a4ab">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -241,7 +241,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="../js/main.js"></script>
|
||||
<script src="../js/main.js?v=ba34a4ab"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user