index.html branding via patch_index.py + per-build x-coop-build marker (SW self-heal); replaces fragile sed chain
This commit is contained in:
1 parent
4b534fcaa2
commit
0468562aa0
2 files changed
+49
-5
No files matched your search
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Inject co-op branding + a per-build marker into the built index.html.
|
||||
|
||||
Non-fatal by design: if the file is missing or upstream changes shape, we
|
||||
exit 0 so a cosmetic patch can never break a version bump.
|
||||
|
||||
The x-coop-build marker makes index.html unique per build, which changes the
|
||||
service worker's precache revision — otherwise stale clients keep running the
|
||||
old cached app shell (the "my changes never deploy" class of bug).
|
||||
"""
|
||||
import time
|
||||
|
||||
PATH = "/app/code/librechat/client/dist/index.html"
|
||||
|
||||
try:
|
||||
html = open(PATH, encoding="utf-8").read()
|
||||
except OSError:
|
||||
raise SystemExit(0)
|
||||
|
||||
# 1. Title
|
||||
html = html.replace("<title>LibreChat</title>", "<title>Inference Co\u2011op</title>")
|
||||
|
||||
# 2. Stylesheet + helper script (idempotent — skip if already present)
|
||||
if "assets/custom.css" not in html:
|
||||
html = html.replace(
|
||||
"</title>",
|
||||
'</title>\n <link rel="stylesheet" href="assets/custom.css">',
|
||||
1,
|
||||
)
|
||||
if "assets/custom2.js" not in html:
|
||||
html = html.replace(
|
||||
'<link rel="stylesheet" href="assets/custom.css">',
|
||||
'<link rel="stylesheet" href="assets/custom.css">\n <script src="assets/custom2.js"></script>',
|
||||
1,
|
||||
)
|
||||
|
||||
# 3. Per-build marker → forces the service worker to refresh the precache
|
||||
if "x-coop-build" not in html:
|
||||
marker = '<meta name="x-coop-build" content="{}">'.format(int(time.time()))
|
||||
html = html.replace("</title>", "</title>\n " + marker, 1)
|
||||
|
||||
open(PATH, "w", encoding="utf-8").write(html)
|
||||
print("index.html: co-op branding + build marker injected")
|
||||
Reference in new issue
Block a user