fix(songs): skip files without wiki.publish:true before validation

Files with no frontmatter or wiki.publish not set should be silently
ignored rather than failing the whole pipeline run.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 18:13:55 +09:00
parent d49b2f0bca
commit 3895cb5c25
+9 -17
View File
@@ -20,10 +20,7 @@ def validate(fm: dict, path: Path) -> None:
if not val or not str(val).strip(): if not val or not str(val).strip():
errors.append(f"missing or empty '{field}'") errors.append(f"missing or empty '{field}'")
wiki = fm.get("wiki") if not isinstance(fm.get("wiki", {}).get("publish"), bool):
if not isinstance(wiki, dict) or "publish" not in wiki:
errors.append("missing 'wiki.publish'")
elif not isinstance(wiki["publish"], bool):
errors.append("'wiki.publish' must be a boolean (true/false), not a string") errors.append("'wiki.publish' must be a boolean (true/false), not a string")
if "release_date" in fm and fm["release_date"]: if "release_date" in fm and fm["release_date"]:
@@ -80,12 +77,8 @@ def connect_wiki() -> mwclient.Site:
def publish_one(rel: Path, post, site: mwclient.Site, source_ref: str, gitea_repo_url: str) -> str: def publish_one(rel: Path, post, site: mwclient.Site, source_ref: str, gitea_repo_url: str) -> str:
"""Returns 'published', 'noop', or 'skipped'.""" """Returns 'published' or 'noop'."""
fm = post.metadata fm = post.metadata
if not fm["wiki"]["publish"]:
return "skipped"
body_wikitext = markdown_to_wikitext(strip_first_h1(post.content)) body_wikitext = markdown_to_wikitext(strip_first_h1(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)
@@ -109,16 +102,19 @@ def load_and_validate(files: list[Path], source_dir: Path) -> dict[Path, object]
continue continue
post = frontmatter.load(str(path)) post = frontmatter.load(str(path))
wiki = post.metadata.get("wiki")
if not isinstance(wiki, dict) or not wiki.get("publish"):
continue
validate(post.metadata, path) validate(post.metadata, path)
if post.metadata["wiki"]["publish"]:
title = str(post.metadata["title"]) title = str(post.metadata["title"])
if title in titles: if title in titles:
raise ValueError( raise ValueError(
f"Duplicate wiki title '{title}': {path} and {titles[title]}" f"Duplicate wiki title '{title}': {path} and {titles[title]}"
) )
titles[title] = path titles[title] = path
posts[path] = post posts[path] = post
return posts return posts
@@ -161,18 +157,14 @@ def main() -> None:
site = connect_wiki() site = connect_wiki()
counts = {"published": 0, "noop": 0, "skipped": 0} counts = {"published": 0, "noop": 0}
for abs_path, post in posts.items(): for abs_path, post in posts.items():
rel = abs_path.relative_to(source_dir) rel = abs_path.relative_to(source_dir)
outcome = publish_one(rel, post, site, source_ref, gitea_repo_url) outcome = publish_one(rel, post, site, source_ref, gitea_repo_url)
counts[outcome] += 1 counts[outcome] += 1
print(f" [{outcome}] {rel}") print(f" [{outcome}] {rel}")
print( print(f"\nDone: {counts['published']} published, {counts['noop']} unchanged.")
f"\nDone: {counts['published']} published, "
f"{counts['noop']} unchanged, "
f"{counts['skipped']} skipped (wiki.publish=false)."
)
if __name__ == "__main__": if __name__ == "__main__":