feat/dossiers-ngi: inject-editions-bar.sh for freeze HTML missing include
This commit is contained in:
parent
b24dd17ee9
commit
3feb694084
9 changed files with 218 additions and 46 deletions
80
scripts/dossiers-ngi/inject-editions-bar.sh
Executable file
80
scripts/dossiers-ngi/inject-editions-bar.sh
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
#!/usr/bin/env bash
|
||||
# Inject cascade-bar include into every editions/<slug> freeze on koopa.
|
||||
# No zypper, no Caddy plugin, no root — hernani must own $WWW.
|
||||
#
|
||||
# bash scripts/dossiers-ngi/inject-editions-bar.sh
|
||||
# WWW=/var/www/monitoring-sites/dossiers.ngi.hacktivism.ch bash …
|
||||
#
|
||||
# Way back without the bar: https://dossiers.ngi.hacktivism.ch/_cascade/use/flask
|
||||
set -euo pipefail
|
||||
|
||||
WWW="${WWW:-/var/www/monitoring-sites/dossiers.ngi.hacktivism.ch}"
|
||||
ED="${ED:-$WWW/editions}"
|
||||
|
||||
if [[ ! -d "$ED" ]]; then
|
||||
echo "FAIL: not a dir: $ED" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
python3 - "$ED" <<'PY'
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
INCLUDE = '{% include "_cascade/bar.html" . %}'
|
||||
BODY_RE = re.compile(r"(<body[^>]*>)", re.IGNORECASE)
|
||||
|
||||
|
||||
def inject(text: str) -> str | None:
|
||||
if INCLUDE in text or "_cascade/bar" in text:
|
||||
return None
|
||||
m = BODY_RE.search(text)
|
||||
if not m:
|
||||
return None
|
||||
i = m.end()
|
||||
return text[:i] + "\n" + INCLUDE + "\n" + text[i:]
|
||||
|
||||
|
||||
root = Path(sys.argv[1]).resolve()
|
||||
scanned = changed = skipped = nobody = 0
|
||||
print(f"ED={root}")
|
||||
for slug_dir in sorted(p for p in root.iterdir() if p.is_dir()):
|
||||
for path in slug_dir.rglob("*.html"):
|
||||
posix = path.as_posix()
|
||||
if "/_cascade/" in posix + "/":
|
||||
continue
|
||||
scanned += 1
|
||||
raw = path.read_text(encoding="utf-8", errors="ignore")
|
||||
if INCLUDE in raw or "_cascade/bar" in raw:
|
||||
skipped += 1
|
||||
continue
|
||||
out = inject(raw)
|
||||
if out is None:
|
||||
nobody += 1
|
||||
print(f"NOBODY {path.relative_to(root)}")
|
||||
continue
|
||||
path.write_text(out, encoding="utf-8")
|
||||
changed += 1
|
||||
print(f"INJECT {path.relative_to(root)}")
|
||||
|
||||
print(f"OK scanned={scanned} injected={changed} already={skipped} nobody={nobody}")
|
||||
if nobody:
|
||||
sys.exit(1)
|
||||
PY
|
||||
|
||||
echo "----- index.html bar? -----"
|
||||
python3 - "$ED" <<'PY'
|
||||
from pathlib import Path
|
||||
import sys
|
||||
root = Path(sys.argv[1])
|
||||
for d in sorted(p for p in root.iterdir() if p.is_dir()):
|
||||
idx = d / "index.html"
|
||||
if not idx.is_file():
|
||||
print(f"MISSING {d.name}/index.html")
|
||||
continue
|
||||
t = idx.read_text(encoding="utf-8", errors="ignore")
|
||||
flag = "BAR" if ("cascade-bar" in t or "_cascade/bar" in t) else "NOBAR"
|
||||
print(f"{flag} {d.name}")
|
||||
PY
|
||||
Loading…
Add table
Add a link
Reference in a new issue