fix(tech): preserve h1 elements — do not strip first heading

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 00:02:02 +09:00
parent 1bfad8332c
commit f7d84b4f0f
3 changed files with 6 additions and 9 deletions
+1 -2
View File
@@ -8,8 +8,7 @@ Publishes tech blog posts from `mikkeli/tech-blogs` to `https://wiki.novoyuuparo
## v1 scope ## v1 scope
- YAML frontmatter parsing per [SCHEMA.md](SCHEMA.md) - YAML frontmatter parsing per [SCHEMA.md](SCHEMA.md)
- Pandoc-based markdown → wikitext body rendering - Pandoc-based markdown → wikitext body rendering (h1 elements preserved)
- First-line h1 stripping
- Auto-generated banner (`{{Auto-generated|source=...|commit=<sha>}}`) - Auto-generated banner (`{{Auto-generated|source=...|commit=<sha>}}`)
- Category injection: `[[Category:Tech blog]]` on every page; `[[Category:Blog:<year>]]` from `date` field; `[[Category:<tag>]]` per tag entry - Category injection: `[[Category:Tech blog]]` on every page; `[[Category:Blog:<year>]]` from `date` field; `[[Category:<tag>]]` per tag entry
- No title prefix — pages live at their bare title - No title prefix — pages live at their bare title
+3 -5
View File
@@ -60,15 +60,14 @@ tags:
## Body ## Body
Plain markdown. The renderer strips the first-line `# Heading` if present (it duplicates the wiki page title), then passes the body through Pandoc. Plain markdown. The body is passed through Pandoc as-is — the first-line `# Heading` is not stripped, so you can use h1 elements freely.
## Renderer behaviour ## Renderer behaviour
For each `.md` with `wiki.publish: true`: For each `.md` with `wiki.publish: true`:
1. Parse and validate frontmatter. 1. Parse and validate frontmatter.
2. Strip the leading `# Heading` from the body if present. 2. Pipe the body through `pandoc -f markdown -t mediawiki`.
3. Pipe the body through `pandoc -f markdown -t mediawiki`.
4. Prepend the auto-generated banner: `{{Auto-generated|source=<source URL>|commit=<sha>}}`. 4. Prepend the auto-generated banner: `{{Auto-generated|source=<source URL>|commit=<sha>}}`.
5. Append category tags: `[[Category:Tech blog]]`; `[[Category:Blog:<year>]]` if `date` is set; `[[Category:<tag>]]` for each tag. 5. Append category tags: `[[Category:Tech blog]]`; `[[Category:Blog:<year>]]` if `date` is set; `[[Category:<tag>]]` for each tag.
6. Read the current wiki page content; if identical, skip the write (idempotency). 6. Read the current wiki page content; if identical, skip the write (idempotency).
@@ -78,8 +77,7 @@ For each `.md` with `wiki.publish: true`:
## Implemented scope ## Implemented scope
- Frontmatter parsing and validation - Frontmatter parsing and validation
- Pandoc-based markdown → wikitext rendering - Pandoc-based markdown → wikitext rendering (h1 elements preserved)
- First-line h1 stripping
- Banner template injection - Banner template injection
- `Category:Tech blog` on every published page - `Category:Tech blog` on every published page
- `Category:Blog:<year>` from `date` field - `Category:Blog:<year>` from `date` field
+2 -2
View File
@@ -11,7 +11,7 @@ import frontmatter
import mwclient import mwclient
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent)) sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
from lib.wiki import AUTO_BANNER_PREFIX, connect_wiki, markdown_to_wikitext, strip_first_h1 from lib.wiki import AUTO_BANNER_PREFIX, connect_wiki, markdown_to_wikitext
def validate(fm: dict, path: Path) -> None: def validate(fm: dict, path: Path) -> None:
@@ -56,7 +56,7 @@ def publish_one(abs_path: Path, source_dir: Path, post, site: mwclient.Site, sou
fm = post.metadata fm = post.metadata
title = str(fm["title"]) title = str(fm["title"])
body_wikitext = markdown_to_wikitext(strip_first_h1(post.content)) body_wikitext = markdown_to_wikitext(post.content)
source_url = f"{gitea_repo_url}/src/commit/{source_ref}/{rel}" source_url = f"{gitea_repo_url}/src/commit/{source_ref}/{rel}"
page_content = build_wikitext(fm, body_wikitext, source_url, source_ref) page_content = build_wikitext(fm, body_wikitext, source_url, source_ref)