Invalidate CSS cache when updated
This commit is contained in:
parent
59688ad5f6
commit
ce80e98d33
3 changed files with 12 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -25,6 +26,14 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
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}"
|
VERSION = f"2.0.0+{VERSION_COMMIT}"
|
||||||
USER_AGENT = f"microblogpub/{VERSION}"
|
USER_AGENT = f"microblogpub/{VERSION}"
|
||||||
|
|
|
@ -26,6 +26,7 @@ from app.actor import LOCAL_ACTOR
|
||||||
from app.ap_object import Attachment
|
from app.ap_object import Attachment
|
||||||
from app.ap_object import Object
|
from app.ap_object import Object
|
||||||
from app.config import BASE_URL
|
from app.config import BASE_URL
|
||||||
|
from app.config import CSS_HASH
|
||||||
from app.config import DEBUG
|
from app.config import DEBUG
|
||||||
from app.config import VERSION
|
from app.config import VERSION
|
||||||
from app.config import generate_csrf_token
|
from app.config import generate_csrf_token
|
||||||
|
@ -102,6 +103,7 @@ async def render_template(
|
||||||
"request": request,
|
"request": request,
|
||||||
"debug": DEBUG,
|
"debug": DEBUG,
|
||||||
"microblogpub_version": VERSION,
|
"microblogpub_version": VERSION,
|
||||||
|
"css_hash": CSS_HASH,
|
||||||
"is_admin": is_admin,
|
"is_admin": is_admin,
|
||||||
"csrf_token": generate_csrf_token(),
|
"csrf_token": generate_csrf_token(),
|
||||||
"highlight_css": HIGHLIGHT_CSS,
|
"highlight_css": HIGHLIGHT_CSS,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<link rel="stylesheet" href="/static/css/main.css">
|
<link rel="stylesheet" href="/static/css/main.css?v={{ css_hash }}">
|
||||||
<link rel="alternate" title="{{ local_actor.display_name}}'s microblog" type="application/json" href="{{ url_for("json_feed") }}" />
|
<link rel="alternate" title="{{ local_actor.display_name}}'s microblog" type="application/json" href="{{ url_for("json_feed") }}" />
|
||||||
<link rel="alternate" href="{{ url_for("rss_feed") }}" type="application/rss+xml" title="{{ local_actor.display_name}}'s microblog">
|
<link rel="alternate" href="{{ url_for("rss_feed") }}" type="application/rss+xml" title="{{ local_actor.display_name}}'s microblog">
|
||||||
<link rel="alternate" href="{{ url_for("atom_feed") }}" type="application/atom+xml" title="{{ local_actor.display_name}}'s microblog">
|
<link rel="alternate" href="{{ url_for("atom_feed") }}" type="application/atom+xml" title="{{ local_actor.display_name}}'s microblog">
|
||||||
|
|
Loading…
Reference in a new issue