fix: spærren godtager kun præcis stempellinjen
canonical() fjernede enhver linje med godkendt: fra det signerede, og Zola kan lukke frontmatter midt på en linje. Sammen gav det plads til ugodkendt tekst i et gyldigt stemplet indlæg. Nu er kun den linje tjenesten skriver usigneret, og kun én gang. Bruger runnerens python3 i stedet for setup-python, som kun har builds til Ubuntu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
aeb7c88949
commit
41e7dacae6
@@ -15,10 +15,6 @@ jobs:
|
|||||||
# Fuld historik til sitemap-lastmod og IndexNow
|
# Fuld historik til sitemap-lastmod og IndexNow
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.12"
|
|
||||||
|
|
||||||
- name: Verify blog approvals
|
- name: Verify blog approvals
|
||||||
env:
|
env:
|
||||||
PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }}
|
PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }}
|
||||||
|
|||||||
+10
-3
@@ -9,13 +9,20 @@ import re
|
|||||||
|
|
||||||
BLOG = "content/blog"
|
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=()):
|
def canonical(rel, text, assets=()):
|
||||||
"""assets: [(sti, sha256-hex)] for billederne i bundlen, sorteret efter sti."""
|
"""assets: [(sti, sha256-hex)] for billederne i bundlen, sorteret efter sti."""
|
||||||
lines = text.replace("\r\n", "\n").split("\n")
|
lines = text.replace("\r\n", "\n").split("\n")
|
||||||
if lines and lines[0] == "---" and "---" in lines[1:]:
|
if lines and lines[0] == "---" and "---" in lines[1:]:
|
||||||
end = lines.index("---", 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)
|
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:
|
if end < 0:
|
||||||
return None, False
|
return None, False
|
||||||
fm = lines[1:end]
|
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)
|
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
|
||||||
|
|||||||
+9
-1
@@ -40,6 +40,14 @@ def old_sign(key, rel, text, assets):
|
|||||||
return "v1:" + hmac.new(key, body.encode(), hashlib.sha256).hexdigest()
|
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):
|
def migrated(text, stamp):
|
||||||
"""Den gamle fil i det nye format: tags under taxonomies, stemplet under extra."""
|
"""Den gamle fil i det nye format: tags under taxonomies, stemplet under extra."""
|
||||||
lines = text.split("\n")
|
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")
|
errors.append(f"{rel}: findes ikke i {args.fra} som {old_rel}; kun godkendelsesflowet må stemple nyt")
|
||||||
continue
|
continue
|
||||||
text = read_text(rel)
|
text = read_text(rel)
|
||||||
stamp_gl, draft = stamp_of(old)
|
stamp_gl, draft = old_stamp(old)
|
||||||
o_assets = old_assets(args.fra, slug)
|
o_assets = old_assets(args.fra, slug)
|
||||||
n_assets = assets_for(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)):
|
if draft or not stamp_gl or not hmac.compare_digest(stamp_gl, old_sign(key, old_rel, old, o_assets)):
|
||||||
|
|||||||
Reference in New Issue
Block a user