Version HTML5 asset URLs
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from html import escape
|
||||
from pathlib import Path
|
||||
from urllib.parse import quote
|
||||
|
||||
_HTML5_ASSETS_DIR = Path(__file__).resolve().parent / "static" / "html5"
|
||||
|
||||
|
||||
def _page(title: str, body: str) -> str:
|
||||
return f"""<!doctype html>
|
||||
@@ -11,14 +14,23 @@ def _page(title: str, body: str) -> str:
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>{escape(title)}</title>
|
||||
<link rel="stylesheet" href="/html5/assets/html5.css" />
|
||||
<script defer src="/html5/assets/htmx.min.js"></script>
|
||||
<script defer src="/html5/assets/htmx-ext-sse.js"></script>
|
||||
<link rel="stylesheet" href="{_asset_url("html5.css")}" />
|
||||
<script defer src="{_asset_url("htmx.min.js")}"></script>
|
||||
<script defer src="{_asset_url("htmx-ext-sse.js")}"></script>
|
||||
</head>
|
||||
<body>{body}</body>
|
||||
</html>"""
|
||||
|
||||
|
||||
def _asset_url(filename: str) -> str:
|
||||
asset_path = _HTML5_ASSETS_DIR / filename
|
||||
try:
|
||||
version = str(int(asset_path.stat().st_mtime))
|
||||
except OSError:
|
||||
version = "dev"
|
||||
return f"/html5/assets/{quote(filename)}?v={version}"
|
||||
|
||||
|
||||
def _project_link(project: object, active_project_id: str) -> str:
|
||||
project_id = str(getattr(project, "project_id", ""))
|
||||
name = str(getattr(project, "name", project_id))
|
||||
|
||||
@@ -140,7 +140,7 @@ _HTML5_ASSETS_DIR = Path(__file__).resolve().parent / "static" / "html5"
|
||||
class Html5StaticFiles(StaticFiles):
|
||||
def file_response(self, *args, **kwargs):
|
||||
response = super().file_response(*args, **kwargs)
|
||||
response.headers.setdefault("Cache-Control", "public, max-age=3600")
|
||||
response.headers.setdefault("Cache-Control", "public, max-age=86400")
|
||||
return response
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user