10 changed files with 239 additions and 121 deletions
@ -0,0 +1,24 @@
|
||||
(function () { |
||||
function applyTheme(theme) { |
||||
document.documentElement.setAttribute("data-theme", theme); |
||||
const toggle = document.getElementById("otbThemeToggle"); |
||||
if (toggle) toggle.checked = theme === "light"; |
||||
} |
||||
|
||||
function savedTheme() { |
||||
return localStorage.getItem("otb_theme") || "dark"; |
||||
} |
||||
|
||||
window.addEventListener("DOMContentLoaded", function () { |
||||
applyTheme(savedTheme()); |
||||
|
||||
const toggle = document.getElementById("otbThemeToggle"); |
||||
if (!toggle) return; |
||||
|
||||
toggle.addEventListener("change", function () { |
||||
const theme = toggle.checked ? "light" : "dark"; |
||||
localStorage.setItem("otb_theme", theme); |
||||
applyTheme(theme); |
||||
}); |
||||
}); |
||||
})(); |
||||
@ -1,41 +1,48 @@
|
||||
#!/bin/bash |
||||
set -e |
||||
|
||||
APP_DIR="/opt/otb_tracker" |
||||
cd "$APP_DIR" || exit 1 |
||||
|
||||
STAMP="$(date +%Y%m%d-%H%M%S)" |
||||
BKDIR="backups/shared-brand-$STAMP" |
||||
mkdir -p "$BKDIR" |
||||
|
||||
cp -av backend/app.py "$BKDIR"/ |
||||
|
||||
HEADER="$(cat /home/def/otb-shared-brand/header.html)" |
||||
FOOTER="$(cat /home/def/otb-shared-brand/footer.html)" |
||||
FOOTER="$(cat /home/def/otb-shared-brand/footer.html | sed 's|__OTB_BRAND_JS__|/static/brand.js|g')" |
||||
BRANDCSS="$(cat /home/def/otb-shared-brand/brand.css)" |
||||
BRANDJS="$(cat /home/def/otb-shared-brand/brand.js)" |
||||
|
||||
python3 - <<PY |
||||
mkdir -p static |
||||
printf '%s |
||||
' "$BRANDJS" > static/brand.js |
||||
|
||||
python3 - <<PY2 |
||||
from pathlib import Path |
||||
import re |
||||
|
||||
app = Path("backend/app.py") |
||||
text = app.read_text(encoding="utf-8") |
||||
|
||||
header = """$HEADER""" |
||||
footer = """$FOOTER""" |
||||
header = '''$HEADER''' |
||||
footer = '''$FOOTER''' |
||||
brandcss = '''$BRANDCSS''' |
||||
|
||||
style_block = f"<style>\n{brandcss}\n</style>" |
||||
|
||||
text = re.sub(r'<style>\s*/\* ===== OTB shared branding ===== \*/.*?</style>', '', text, flags=re.S) |
||||
|
||||
# inject header |
||||
if header not in text: |
||||
text = text.replace("<body>", "<body>\\n" + header) |
||||
text = text.replace("<body>", "<body>\n" + header) |
||||
|
||||
# inject footer |
||||
if footer not in text: |
||||
text = text.replace("</body>", footer + "\\n</body>") |
||||
text = text.replace("</body>", footer + "\n</body>") |
||||
|
||||
if style_block not in text: |
||||
text = text.replace("</head>", style_block + "\n</head>") |
||||
|
||||
app.write_text(text, encoding="utf-8") |
||||
print("otb-tracker branding injected") |
||||
PY |
||||
|
||||
echo "==== restarting service ====" |
||||
sudo systemctl restart otb_tracker.service || true |
||||
PY2 |
||||
|
||||
echo "==== done ====" |
||||
sudo systemctl restart otb-tracker.service || true |
||||
|
||||
Loading…
Reference in new issue