diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 2c5564d..745d58f 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -15,10 +15,6 @@ jobs: # Fuld historik til sitemap-lastmod og IndexNow fetch-depth: 0 - - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - name: Verify blog approvals env: PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }} diff --git a/scripts/godkendelse.py b/scripts/godkendelse.py index 1ddca0d..9b48160 100755 --- a/scripts/godkendelse.py +++ b/scripts/godkendelse.py @@ -9,13 +9,20 @@ import re BLOG = "content/blog" +# Præcis den linje tjenesten skriver. Alt andet i filen er signeret, også linjer der +# ligner stemplet. Zola og dette script kan være uenige om hvor frontmatter slutter, så +# en løsere regel ville give plads til usigneret tekst. +STAMP_LINE = re.compile(r' godkendt: "(v1:[0-9a-f]{64})"') + def canonical(rel, text, assets=()): """assets: [(sti, sha256-hex)] for billederne i bundlen, sorteret efter sti.""" lines = text.replace("\r\n", "\n").split("\n") if lines and lines[0] == "---" and "---" in lines[1:]: end = lines.index("---", 1) - lines = [l for i, l in enumerate(lines) if not (0 < i < end and re.match(r"\s*godkendt:", l))] + hit = next((i for i in range(1, end) if STAMP_LINE.fullmatch(lines[i])), None) + if hit: + del lines[hit] return f"{rel}\n" + "\n".join(lines) + "".join(f"\n@asset {p} {h}" for p, h in assets) @@ -56,6 +63,6 @@ def stamp_of(text): if end < 0: return None, False fm = lines[1:end] - g = next((l for l in fm if re.match(r"\s*godkendt:", l)), None) + g = next((m for m in map(STAMP_LINE.fullmatch, fm) if m), None) draft = any(re.fullmatch(r"draft:\s*true\s*", l) for l in fm) - return (re.sub(r"^\s*godkendt:\s*", "", g).strip("'\"") if g else None), draft + return (g[1] if g else None), draft diff --git a/scripts/omstempl.py b/scripts/omstempl.py index 677b1b0..7bfdede 100755 --- a/scripts/omstempl.py +++ b/scripts/omstempl.py @@ -40,6 +40,14 @@ def old_sign(key, rel, text, assets): return "v1:" + hmac.new(key, body.encode(), hashlib.sha256).hexdigest() +def old_stamp(text): + """(stempel eller None, draft) i det gamle format.""" + head = text.split("\n---\n", 1)[0].split("\n") + g = next((l for l in head if l.startswith("godkendt:")), None) + stamp = re.sub(r"^godkendt:\s*", "", g).strip("'\"") if g else None + return stamp, any(re.fullmatch(r"draft:\s*true\s*", l) for l in head) + + def migrated(text, stamp): """Den gamle fil i det nye format: tags under taxonomies, stemplet under extra.""" lines = text.split("\n") @@ -76,7 +84,7 @@ def main(): errors.append(f"{rel}: findes ikke i {args.fra} som {old_rel}; kun godkendelsesflowet må stemple nyt") continue text = read_text(rel) - stamp_gl, draft = stamp_of(old) + stamp_gl, draft = old_stamp(old) o_assets = old_assets(args.fra, slug) n_assets = assets_for(slug) if draft or not stamp_gl or not hmac.compare_digest(stamp_gl, old_sign(key, old_rel, old, o_assets)):