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

Songs always carries a # Song title line so stripping makes sense there,
but SES body structure is freeform and may use h1 deliberately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 00:00:08 +09:00
parent dfe1f9c631
commit 230a3badc3
3 changed files with 6 additions and 9 deletions
-1
View File
@@ -10,7 +10,6 @@ Publishes SES light novel pages from `mikkeli/ses-light-novel` to `https://wiki.
- YAML frontmatter parsing per [SCHEMA.md](SCHEMA.md)
- `SES:` title prefix — all pages live in the SES MediaWiki namespace
- Pandoc-based markdown → wikitext body rendering
- First-line h1 stripping
- Auto-generated banner (`{{Auto-generated|source=...|commit=<sha>}}`)
- Category injection: `[[Category:SES]]` + `[[Category:SES:<type>]]` on every page; type from `type:` field, falling back to the file's parent directory name
- Additional categories via optional `categories` list
+4 -6
View File
@@ -20,7 +20,7 @@ wiki:
... body markdown ...
```
The renderer parses the frontmatter, validates required fields, strips the first `# Heading` line if present, then hands the body to Pandoc.
The renderer parses the frontmatter, validates required fields, then hands the body to Pandoc. The first-line `# Heading` is preserved — use it if you want an h1 on the rendered page.
## Fields
@@ -69,15 +69,14 @@ categories:
## Body
Plain markdown. The renderer strips the first-line `# Heading` if present, then passes the body through Pandoc. Do not embed raw wikitext (`{{Template}}`, raw `[[Wikilinks]]`, etc.) unless you intend the literal output.
Plain markdown. The body is passed through Pandoc as-is — the first-line `# Heading` is not stripped, so you can use h1 elements freely. Do not embed raw wikitext (`{{Template}}`, raw `[[Wikilinks]]`, etc.) unless you intend the literal output.
## Renderer behaviour
For each `.md` with `wiki.publish: true`:
1. Parse and validate frontmatter.
2. Strip the leading `# Heading` from the body if present.
3. Pipe the body through `pandoc -f markdown -t mediawiki`.
2. Pipe the body through `pandoc -f markdown -t mediawiki`.
4. Prepend the auto-generated banner: `{{Auto-generated|source=<source URL>|commit=<sha>}}`.
5. Append category tags: `[[Category:SES]]`, `[[Category:SES:<type>]]`, and any entries from `categories`.
6. Read the current wiki page content via the MediaWiki API; if identical to the generated output, skip the write (idempotency).
@@ -88,8 +87,7 @@ For each `.md` with `wiki.publish: true`:
- Frontmatter parsing and validation
- `SES:` title prefix
- Pandoc-based markdown → wikitext body rendering
- First-line h1 stripping
- Pandoc-based markdown → wikitext body rendering (h1 elements preserved)
- Banner template injection
- `Category:SES` + `Category:SES:<type>` injection (type from frontmatter, fallback to parent directory)
- Additional categories via `categories` list
+2 -2
View File
@@ -10,7 +10,7 @@ import frontmatter
import mwclient
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:
@@ -58,7 +58,7 @@ def publish_one(abs_path: Path, source_dir: Path, post, site: mwclient.Site, sou
title = get_page_title(fm)
page_type = get_page_type(fm, abs_path, source_dir)
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}"
page_content = build_wikitext(fm, body_wikitext, source_url, source_ref, page_type)