Files
Paul HittandClaude Fable 5.1 e15beaf9a9 Second pass with the avoid-ai-writing detector
The skill's own detector (conorbronsdon/avoid-ai-writing) scored every
README, doc, page and the extracted comment prose. Scores were already
0 to 3 out of 100; what it still flagged is fixed here: hollow
intensifiers (genuinely, genuine), "in order to", "additionally",
"the whole point" and "the entire point", bold sentences of seven words
or more in the docs, and bold that had wrapped across comment lines.

Comment prose now scores a maximum of 1 out of 100 across the repo.

One rule in the sweep went wrong and was caught by reading the diff:
"which is the entire point of X" lost its clause and left "of X"
dangling in four comments. Repaired by hand; the rule now keeps the
clause when it is followed by "of".

Comments and strings only. 694 tests pass.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-08 19:19:52 -04:00

76 lines
3.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""Wrap a pandoc HTML fragment as a Leaf page that extends the site layout.
Usage: md2leaf.py <slug> <html-fragment-file> <views-dir> [shown-path] [real-source]
"""
import hashlib
import sys
slug, src, views = sys.argv[1], sys.argv[2], sys.argv[3]
source = sys.argv[4] if len(sys.argv) > 4 else "a markdown source"
# The markdown this page was built from, hashed into the banner so
# `check-doc-pages.py` can tell whether the page is still current WITHOUT
# running pandoc. Checking by re-rendering would make CI hostage to the pandoc
# version: a different release emits different HTML, and the job would fail on
# machines where nothing is actually wrong.
real = sys.argv[5] if len(sys.argv) > 5 else None
digest = (hashlib.sha256(open(real, "rb").read()).hexdigest()[:16]
if real else "unknown")
body = open(src, encoding="utf-8").read()
# The documents refer to the deployed site absolutely. On the site itself that
# is a link that leaves and comes back, so it is rewritten to a relative one.
body = body.replace('href="https://flamenetmessenger.com"', 'href="/"')
body = body.replace('href="https://flamenetmessenger.com/', 'href="/')
# Leaf treats `#` as the start of a tag, and these documents are full of them:
# heading anchors, shell comments, `#8` cross-references. Escape every one to a
# literal. Single pass, so the `#` this inserts is not itself re-scanned.
body = body.replace("#", '#("#")')
# A banner, because this file has been hand-edited before and the edits
# were silently destroyed. `self-hosting.leaf` grew a hundred lines of
# useful prose, the amd64 note, the update instructions, written
# straight into the generated output. Nobody re-ran this script for a month, so
# nothing complained; the next run would have deleted all of it, with no error
# and no diff anybody was looking at.
#
# The banner cannot prevent that. It can make the next person open the file,
# see where the words actually come from, and edit the markdown instead.
#
# An HTML comment, not a Leaf one, and placed INSIDE the exported content.
# Leaf treats
# `#` as a tag opener, so a comment written in its own syntax is a thing that
# has to parse; a plain HTML comment cannot fail to render and cannot change
# what the page looks like. Inside the content rather than above `#extend` so it
# lands in the body, well after the doctype, where no parser has an opinion
# about it. It costs three lines in the served source.
#
# The banner also carries a hash of the source, and that is not decoration:
# it is the only thing that catches the OPPOSITE failure. The warning above
# guards edits made here, which fail loudly because they vanish. A source
# edited and the page never regenerated fails silently and stays served,
# which is what happened to /self-hosting, live for a day with instructions
# that did not work.
BANNER = (
"<!-- GENERATED by Scripts/build-doc-pages.sh from {source}.\n"
" Edits made HERE are deleted the next time that script runs.\n"
" Change the markdown source and re-run it.\n"
" source-sha256: {digest} -->\n"
)
out = (
'#extend("layout"):\n'
'#export("content"):\n' +
BANNER.format(source=source, digest=digest) +
'<article class="band doc doc-generated">\n'
' <div class="wrap wrap-narrow">\n'
f"{body}\n"
" </div>\n"
"</article>\n"
"#endexport\n"
"#endextend\n"
)
open(f"{views}/{slug}.leaf", "w", encoding="utf-8").write(out)
print(f" {slug}.leaf ({len(body.splitlines())} lines)")