master
John Lauer Update 5 file(s) 60bbff0 2mo ago
#!/bin/bash
# Regenerate the rendered page body from SKILL.md so the wiki page and the installed skill can
# never drift apart again. They drifted to 10,712 vs 21,144 bytes -- and into contradicting each
# other -- precisely because both were authored by hand. Run this before every publish.
#
# WHERE THE RENDERED PAGE ACTUALLY COMES FROM (learned the hard way, John 2026-07-24):
#   `adom-wiki pkg publish` renders the page body from **README.md in the tarball** and IGNORES
#   page.json entirely (it warns PAGE_JSON_IGNORED). It also refuses to shrink a page: if the
#   tarball README is smaller than the already-rendered body it keeps the old one (README_PRESERVED).
#   So the earlier "README.md is just a pointer, page.json.readme is what the wiki reads" design was
#   WRONG -- syncing page.json did nothing to the live page. README.md IS the page. We generate BOTH
#   README.md (the render source) and page.json.readme (kept in lockstep for repo-push consumers)
#   from SKILL.md, the single source of truth.
set -e
cd "$(dirname "$0")"
python3 - <<'PY'
import json, re
skill = open('SKILL.md').read()
body = skill.split('---', 2)[2].lstrip('\n')          # strip frontmatter, keep the glossary

# 1) README.md — the file pkg publish actually renders as the page body. A leading banner marks
#    it generated so nobody hand-edits it (edit SKILL.md instead), then the full glossary.
banner = ("<!-- GENERATED FROM SKILL.md by sync-page-readme.sh. Do not edit by hand: edit SKILL.md,\n"
          "     then run ./sync-page-readme.sh before publishing. README.md IS the rendered wiki\n"
          "     page body (pkg publish renders README.md, not page.json). -->\n\n")
open('README.md', 'w').write(banner + body)

# 2) page.json.readme — kept in lockstep for repo-push / page-repo consumers, even though
#    pkg publish ignores it.
pg = json.load(open('page.json'))
before = len(pg.get('readme', ''))
pg['readme'] = body
json.dump(pg, open('page.json', 'w'), indent=2)

terms = len(re.findall(r'^\|\s*\*\*', body, re.M))
print(f"README.md: {len(banner)+len(body)} bytes | page.json readme: {before} -> {len(body)} bytes | {terms} terms (source: SKILL.md)")
PY