From ce80e98d33f36ac8818dded45aaac9bafc9fb65a Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 13 Aug 2022 15:35:39 +0200 Subject: [PATCH] Invalidate CSS cache when updated --- app/config.py | 9 +++++++++ app/templates.py | 2 ++ app/templates/layout.html | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/config.py b/app/config.py index f828f6d..9578d08 100644 --- a/app/config.py +++ b/app/config.py @@ -1,3 +1,4 @@ +import hashlib import os import secrets from pathlib import Path @@ -25,6 +26,14 @@ try: except ImportError: pass +# Force reloading cache when the CSS is updated +CSS_HASH = "none" +try: + css_data = (ROOT_DIR / "app" / "static" / "css" / "main.css").read_bytes() + CSS_HASH = hashlib.md5(css_data, usedforsecurity=False).hexdigest() +except FileNotFoundError: + pass + VERSION = f"2.0.0+{VERSION_COMMIT}" USER_AGENT = f"microblogpub/{VERSION}" diff --git a/app/templates.py b/app/templates.py index c1f4ec1..30bd759 100644 --- a/app/templates.py +++ b/app/templates.py @@ -26,6 +26,7 @@ from app.actor import LOCAL_ACTOR from app.ap_object import Attachment from app.ap_object import Object from app.config import BASE_URL +from app.config import CSS_HASH from app.config import DEBUG from app.config import VERSION from app.config import generate_csrf_token @@ -102,6 +103,7 @@ async def render_template( "request": request, "debug": DEBUG, "microblogpub_version": VERSION, + "css_hash": CSS_HASH, "is_admin": is_admin, "csrf_token": generate_csrf_token(), "highlight_css": HIGHLIGHT_CSS, diff --git a/app/templates/layout.html b/app/templates/layout.html index 940378d..0124969 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -4,7 +4,7 @@ - +