fix: improve release visibility and cache handling
This commit is contained in:
@@ -75,23 +75,32 @@ BUILD_INFO = load_build_info()
|
||||
|
||||
|
||||
def load_whats_new_summary():
|
||||
"""Load compact release notes for the What's New dialog."""
|
||||
"""Load compact release-note metadata for the What's New dialog."""
|
||||
try:
|
||||
with open(WHATS_NEW_SUMMARY_FILE, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
except Exception as e:
|
||||
print(f"[What's New Error] {e}")
|
||||
return []
|
||||
return {"version": "unknown", "items": []}
|
||||
|
||||
items = data.get("items") if isinstance(data, dict) else None
|
||||
if not isinstance(data, dict):
|
||||
return {"version": "unknown", "items": []}
|
||||
|
||||
version = data.get("version")
|
||||
items = data.get("items")
|
||||
if not isinstance(items, list):
|
||||
return []
|
||||
items = []
|
||||
|
||||
return [
|
||||
item.strip()
|
||||
for item in items
|
||||
if isinstance(item, str) and item.strip()
|
||||
][:5]
|
||||
return {
|
||||
"version": version.strip()
|
||||
if isinstance(version, str) and version.strip()
|
||||
else "unknown",
|
||||
"items": [
|
||||
item.strip()
|
||||
for item in items
|
||||
if isinstance(item, str) and item.strip()
|
||||
][:5]
|
||||
}
|
||||
|
||||
|
||||
WHATS_NEW_SUMMARY = load_whats_new_summary()
|
||||
@@ -101,9 +110,36 @@ def inject_build_info():
|
||||
"""Make build metadata and release-note summary available in templates."""
|
||||
return {
|
||||
"build_info": BUILD_INFO,
|
||||
"whats_new_summary": WHATS_NEW_SUMMARY
|
||||
"whats_new_summary": WHATS_NEW_SUMMARY,
|
||||
"static_asset_url": static_asset_url
|
||||
}
|
||||
|
||||
|
||||
def get_static_asset_version(build_info=None):
|
||||
"""Return the preferred cache-busting build identifier."""
|
||||
info = build_info or BUILD_INFO
|
||||
for key in ("commit", "version"):
|
||||
value = info.get(key) if isinstance(info, dict) else None
|
||||
if isinstance(value, str) and value.strip() and value.strip() != "unknown":
|
||||
return value.strip()
|
||||
return None
|
||||
|
||||
|
||||
def static_asset_url(filename):
|
||||
"""Build a URL for RollCalc-owned static assets with a build query."""
|
||||
asset_version = get_static_asset_version()
|
||||
if asset_version:
|
||||
return url_for("serve_static", filename=filename, v=asset_version)
|
||||
return url_for("serve_static", filename=filename)
|
||||
|
||||
|
||||
@app.after_request
|
||||
def add_html_cache_policy(response):
|
||||
"""Require revalidation for dynamic HTML while leaving static caching intact."""
|
||||
if response.mimetype == "text/html":
|
||||
response.headers["Cache-Control"] = "no-cache"
|
||||
return response
|
||||
|
||||
# ============================================================================
|
||||
# AUTHENTICATION
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user