fix: use filename as fallback source when article has no H1 title

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
wangzhuc 2026-03-30 22:42:23 +08:00
parent 885cae8e7d
commit 83c963527c

View file

@ -178,7 +178,7 @@ def extract_exemplar(text, category=None, source=None):
paragraphs = hs._split_paragraphs(text) paragraphs = hs._split_paragraphs(text)
sentences = hs._split_sentences(clean) sentences = hs._split_sentences(clean)
headings = extract_headings(text) headings = extract_headings(text)
title = extract_title(text) or source or "untitled" title = extract_title(text) or source or ""
if not category: if not category:
category = detect_category(clean, paragraphs, headings) category = detect_category(clean, paragraphs, headings)
@ -349,7 +349,8 @@ def main():
continue continue
text = path.read_text(encoding="utf-8") text = path.read_text(encoding="utf-8")
exemplar = extract_exemplar(text, category=args.category, source=args.source) source = args.source or path.stem # fallback to filename without extension
exemplar = extract_exemplar(text, category=args.category, source=source)
filepath = save_exemplar(exemplar) filepath = save_exemplar(exemplar)
if args.json: if args.json: