landing: per-site content versions (bank/exchange/merchant v42)
Independent version counters per landing footer with last-change time and linkified commit; stamp script takes bank|exchange|merchant|--all.
This commit is contained in:
parent
1bbdc2d1ae
commit
bdfdbfe7c8
6 changed files with 170 additions and 92 deletions
|
|
@ -1,57 +1,83 @@
|
|||
#!/usr/bin/env bash
|
||||
# Stamp landing footers with version + last content change + linkified commit.
|
||||
# Stamp landing footers per site: version + last content change + linkified commit.
|
||||
#
|
||||
# Sites: bank | exchange | merchant
|
||||
#
|
||||
# Usage (from koopa-admin-log root):
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh # re-stamp with HEAD + current version
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh --bump # version += 1, then stamp HEAD
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh --set 42 # force version
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh bank
|
||||
# re-stamp bank with current version + HEAD
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh --bump bank
|
||||
# bank version += 1, then stamp HEAD
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh --set 42 exchange
|
||||
# force exchange version to 42
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh --all
|
||||
# re-stamp all sites (no bump)
|
||||
# ./scripts/taler-landing/stamp-landing-version.sh --bump --all
|
||||
# bump every site by 1 (rare)
|
||||
#
|
||||
# Typical flow after editing landing HTML/CSS/JS:
|
||||
# 1) edit landings
|
||||
# 2) ./scripts/taler-landing/stamp-landing-version.sh --bump
|
||||
# 3) git add configs/ && git commit
|
||||
# 4) ./scripts/taler-landing/stamp-landing-version.sh && git add configs/ && git commit --amend --no-edit
|
||||
#
|
||||
# Or one-shot (commits for you if GIT_STAMP_COMMIT=1).
|
||||
# Typical flow after editing one site:
|
||||
# 1) edit configs/bank-landing/…
|
||||
# 2) ./scripts/taler-landing/stamp-landing-version.sh --bump bank
|
||||
# 3) git add configs/ && git commit -m "landing(bank): …"
|
||||
# 4) ./scripts/taler-landing/stamp-landing-version.sh bank
|
||||
# git add configs/ && git commit --amend --no-edit # optional pin
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
VER_FILE="$ROOT/configs/shared/landing-version.json"
|
||||
REPO_WEB="${LANDING_REPO_WEB:-https://git.hacktivism.ch/hernani/koopa-admin-log}"
|
||||
LANDINGS=(
|
||||
"$ROOT/configs/bank-landing/index.html"
|
||||
"$ROOT/configs/exchange-landing/index.html"
|
||||
"$ROOT/configs/merchant-landing/index.html"
|
||||
|
||||
declare -A SITE_HTML=(
|
||||
[bank]="$ROOT/configs/bank-landing/index.html"
|
||||
[exchange]="$ROOT/configs/exchange-landing/index.html"
|
||||
[merchant]="$ROOT/configs/merchant-landing/index.html"
|
||||
)
|
||||
declare -A SITE_LABEL=(
|
||||
[bank]="Bank landing"
|
||||
[exchange]="Exchange landing"
|
||||
[merchant]="Merchant landing"
|
||||
)
|
||||
declare -A SITE_PATH=(
|
||||
[bank]="configs/bank-landing"
|
||||
[exchange]="configs/exchange-landing"
|
||||
[merchant]="configs/merchant-landing"
|
||||
)
|
||||
|
||||
export TZ="${TZ:-Europe/Zurich}"
|
||||
|
||||
bump=0
|
||||
set_ver=""
|
||||
do_all=0
|
||||
sites=()
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--bump) bump=1; shift ;;
|
||||
--set) set_ver="${2:-}"; shift 2 ;;
|
||||
--all) do_all=1; shift ;;
|
||||
bank|exchange|merchant) sites+=("$1"); shift ;;
|
||||
-h|--help)
|
||||
sed -n '2,20p' "$0"
|
||||
sed -n '2,28p' "$0"
|
||||
exit 0
|
||||
;;
|
||||
*) echo "unknown arg: $1" >&2; exit 2 ;;
|
||||
*) echo "unknown arg: $1 (sites: bank exchange merchant)" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$do_all" = 1 ]; then
|
||||
sites=(bank exchange merchant)
|
||||
fi
|
||||
if [ "${#sites[@]}" -eq 0 ]; then
|
||||
echo "usage: $0 [--bump|--set N] bank|exchange|merchant|--all" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ! -f "$VER_FILE" ]; then
|
||||
echo '{"version":42,"updated_iso":"","updated_human":"","commit":"","commit_short":""}' >"$VER_FILE"
|
||||
cat >"$VER_FILE" <<'EOF'
|
||||
{"note":"per-site","sites":{"bank":{"version":42},"exchange":{"version":42},"merchant":{"version":42}}}
|
||||
EOF
|
||||
fi
|
||||
|
||||
version=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("version",42))' "$VER_FILE")
|
||||
if [ -n "$set_ver" ]; then
|
||||
version="$set_ver"
|
||||
elif [ "$bump" = 1 ]; then
|
||||
version=$((version + 1))
|
||||
fi
|
||||
|
||||
# Prefer staged/index commit identity after commit; allow OVERRIDE_COMMIT
|
||||
if [ -n "${OVERRIDE_COMMIT:-}" ]; then
|
||||
full="$OVERRIDE_COMMIT"
|
||||
else
|
||||
|
|
@ -62,34 +88,6 @@ iso=$(date +%Y-%m-%dT%H:%M:%S%z | sed -E 's/([+-][0-9]{2})([0-9]{2})$/\1:\2/')
|
|||
human=$(date +"%Y-%m-%d %H:%M %Z")
|
||||
url="${REPO_WEB}/commit/${full}"
|
||||
|
||||
python3 - "$VER_FILE" "$version" "$iso" "$human" "$full" "$short" "$url" <<'PY'
|
||||
import json, sys
|
||||
path, version, iso, human, full, short, url = sys.argv[1:]
|
||||
data = {
|
||||
"version": int(version),
|
||||
"updated_iso": iso,
|
||||
"updated_human": human,
|
||||
"commit": full,
|
||||
"commit_short": short,
|
||||
"repo_commit_url": url,
|
||||
"note": "Bump with scripts/taler-landing/stamp-landing-version.sh --bump after each landing content change.",
|
||||
}
|
||||
open(path, "w", encoding="utf-8").write(json.dumps(data, indent=2, ensure_ascii=False) + "\n")
|
||||
print(f"version={version} commit={short} at={human}")
|
||||
PY
|
||||
|
||||
# HTML block injected into each footer (idempotent via markers)
|
||||
block=$(cat <<EOF
|
||||
<!-- landing-rev -->
|
||||
<p class="landing-rev" data-landing-version="${version}" data-landing-commit="${short}">
|
||||
Landing <strong>v${version}</strong>
|
||||
· content <time datetime="${iso}">${human}</time>
|
||||
· <a href="${url}" title="koopa-admin-log ${full}">${short}</a>
|
||||
</p>
|
||||
<!-- /landing-rev -->
|
||||
EOF
|
||||
)
|
||||
|
||||
css_snip=' .landing-rev {
|
||||
margin: 0.75rem 0 0;
|
||||
font-size: 0.72rem;
|
||||
|
|
@ -101,27 +99,80 @@ css_snip=' .landing-rev {
|
|||
.landing-rev strong { font-weight: 750; }
|
||||
'
|
||||
|
||||
for f in "${LANDINGS[@]}"; do
|
||||
[ -f "$f" ] || { echo "missing $f" >&2; exit 1; }
|
||||
for site in "${sites[@]}"; do
|
||||
html="${SITE_HTML[$site]:-}"
|
||||
label="${SITE_LABEL[$site]:-}"
|
||||
relpath="${SITE_PATH[$site]:-}"
|
||||
[ -n "$html" ] && [ -f "$html" ] || { echo "missing site/html: $site" >&2; exit 1; }
|
||||
|
||||
# resolve version for this site
|
||||
version=$(python3 - "$VER_FILE" "$site" "$bump" "$set_ver" <<'PY'
|
||||
import json, sys
|
||||
path, site, bump, set_ver = sys.argv[1:5]
|
||||
data = json.load(open(path, encoding="utf-8"))
|
||||
sites = data.setdefault("sites", {})
|
||||
entry = sites.setdefault(site, {"version": 42})
|
||||
v = int(entry.get("version", 42))
|
||||
if set_ver:
|
||||
v = int(set_ver)
|
||||
elif bump == "1":
|
||||
v += 1
|
||||
print(v)
|
||||
PY
|
||||
)
|
||||
|
||||
# update JSON entry for this site (preserve others)
|
||||
python3 - "$VER_FILE" "$site" "$version" "$label" "$relpath" "$iso" "$human" "$full" "$short" "$url" <<'PY'
|
||||
import json, sys
|
||||
path, site, version, label, relpath, iso, human, full, short, url = sys.argv[1:]
|
||||
data = json.load(open(path, encoding="utf-8"))
|
||||
data["note"] = (
|
||||
"Per-site landing content versions (start 42). "
|
||||
"Bump: scripts/taler-landing/stamp-landing-version.sh --bump bank|exchange|merchant"
|
||||
)
|
||||
sites = data.setdefault("sites", {})
|
||||
sites[site] = {
|
||||
"version": int(version),
|
||||
"label": label,
|
||||
"path": relpath,
|
||||
"updated_iso": iso,
|
||||
"updated_human": human,
|
||||
"commit": full,
|
||||
"commit_short": short,
|
||||
"repo_commit_url": url,
|
||||
}
|
||||
open(path, "w", encoding="utf-8").write(json.dumps(data, indent=2, ensure_ascii=False) + "\n")
|
||||
print(f"{site}: v{version} commit={short} at={human}")
|
||||
PY
|
||||
|
||||
block=$(cat <<EOF
|
||||
<!-- landing-rev -->
|
||||
<p class="landing-rev" data-landing-site="${site}" data-landing-version="${version}" data-landing-commit="${short}">
|
||||
${label} <strong>v${version}</strong>
|
||||
· content <time datetime="${iso}">${human}</time>
|
||||
· <a href="${url}" title="koopa-admin-log ${full}">${short}</a>
|
||||
</p>
|
||||
<!-- /landing-rev -->
|
||||
EOF
|
||||
)
|
||||
|
||||
# ensure CSS once
|
||||
if ! grep -q '\.landing-rev' "$f"; then
|
||||
# insert before </style> of first style block
|
||||
python3 - "$f" "$css_snip" <<'PY'
|
||||
if ! grep -q '\.landing-rev' "$html"; then
|
||||
python3 - "$html" "$css_snip" <<'PY'
|
||||
import sys
|
||||
path, snip = sys.argv[1], sys.argv[2]
|
||||
t = open(path, encoding="utf-8").read()
|
||||
if ".landing-rev" in t:
|
||||
sys.exit(0)
|
||||
raise SystemExit(0)
|
||||
idx = t.find("</style>")
|
||||
if idx < 0:
|
||||
raise SystemExit(f"no </style> in {path}")
|
||||
t = t[:idx] + snip + "\n" + t[idx:]
|
||||
open(path, "w", encoding="utf-8").write(t)
|
||||
open(path, "w", encoding="utf-8").write(t[:idx] + snip + "\n" + t[idx:])
|
||||
print(f"css → {path}")
|
||||
PY
|
||||
fi
|
||||
# replace or insert rev block before </footer>
|
||||
python3 - "$f" "$block" <<'PY'
|
||||
|
||||
python3 - "$html" "$block" <<'PY'
|
||||
import sys, re
|
||||
path, block = sys.argv[1], sys.argv[2]
|
||||
t = open(path, encoding="utf-8").read()
|
||||
|
|
@ -130,7 +181,6 @@ pat = re.compile(r"[ \t]*<!-- landing-rev -->.*?<!-- /landing-rev -->\n?", re.S)
|
|||
if pat.search(t):
|
||||
t = pat.sub(block, t, count=1)
|
||||
else:
|
||||
# before closing footer
|
||||
t2, n = re.subn(r"(\n)([ \t]*</footer>)", r"\1" + block + r"\2", t, count=1)
|
||||
if n != 1:
|
||||
raise SystemExit(f"could not insert landing-rev in {path}")
|
||||
|
|
@ -140,4 +190,4 @@ print(f"stamp → {path}")
|
|||
PY
|
||||
done
|
||||
|
||||
echo "OK landing v${version} → ${short} (${human})"
|
||||
echo "OK stamped: ${sites[*]}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue