feat(ses): add SES light novel pipeline; extract shared lib/wiki.py
New pipeline at pipelines/ses/ publishes mikkeli/ses-light-novel to the SES: MediaWiki namespace. All pages get Category:SES and Category:SES:<type> (type from frontmatter, fallback to parent dir name). Shared functions (connect_wiki, markdown_to_wikitext, strip_first_h1, AUTO_BANNER_PREFIX) extracted from songs/publish.py into lib/wiki.py; songs refactored to import from there. Also adds publish-ses.yml workflow stub and updates Dockerfile and root README. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
"""Shared utilities for novoyuuparosk-auto-wiki pipelines."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import mwclient
|
||||
|
||||
AUTO_BANNER_PREFIX = "{{Auto-generated"
|
||||
|
||||
|
||||
def strip_first_h1(text: str) -> str:
|
||||
"""Remove the first '# Heading' line and any immediately following blank line."""
|
||||
lines = text.split("\n")
|
||||
for i, line in enumerate(lines):
|
||||
if line.strip().startswith("# "):
|
||||
del lines[i]
|
||||
if i < len(lines) and lines[i].strip() == "":
|
||||
del lines[i]
|
||||
break
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def markdown_to_wikitext(body: str) -> str:
|
||||
result = subprocess.run(
|
||||
["pandoc", "-f", "markdown", "-t", "mediawiki"],
|
||||
input=body,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"pandoc failed: {result.stderr.strip()}")
|
||||
return result.stdout
|
||||
|
||||
|
||||
def connect_wiki() -> mwclient.Site:
|
||||
api_url = os.environ["WIKI_API_URL"]
|
||||
parsed = urlparse(api_url)
|
||||
host = parsed.netloc
|
||||
path = parsed.path[: parsed.path.rfind("/") + 1] or "/"
|
||||
site = mwclient.Site(host, path=path, scheme=parsed.scheme)
|
||||
site.login(os.environ["WIKI_BOT_USER"], os.environ["WIKI_BOT_PASSWORD"])
|
||||
return site
|
||||
Reference in New Issue
Block a user