diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-03 10:01:57 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-03 10:01:57 +0200 |
| commit | 823703d848e810ee1dbe00d5470c60302a59a422 (patch) | |
| tree | c28043a609ad4d3168ba27146df8c6d779131c6b /core | |
| parent | df09c8dc84c7df2ba589c486b801454290a2b404 (diff) | |
| download | publisher-823703d848e810ee1dbe00d5470c60302a59a422.tar.gz publisher-823703d848e810ee1dbe00d5470c60302a59a422.zip | |
feat: article scanner with translation pair detection
Diffstat (limited to 'core')
| -rw-r--r-- | core/article_scanner.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/article_scanner.py b/core/article_scanner.py new file mode 100644 index 0000000..ea6579a --- /dev/null +++ b/core/article_scanner.py @@ -0,0 +1,34 @@ +from __future__ import annotations +from pathlib import Path +from core.models import Article +from core.frontmatter import parse_frontmatter + +def scan_articles(blog_root: Path) -> list[Article]: + articles: list[Article] = [] + by_slug: dict[tuple[str, str], Path] = {} + + for lang in ("it", "en"): + content_dir = blog_root / "content" / lang / "articles" + if not content_dir.exists(): + continue + for index_md in sorted(content_dir.glob("*/index.md")): + slug = index_md.parent.name + by_slug[(lang, slug)] = index_md + + for (lang, slug), path in by_slug.items(): + other_lang = "en" if lang == "it" else "it" + translation_path = by_slug.get((other_lang, slug)) + try: + fm, _ = parse_frontmatter(path) + except (ValueError, Exception): + fm = {} + articles.append(Article( + slug=slug, + lang=lang, + path=path, + frontmatter=fm, + has_translation=translation_path is not None, + translation_path=translation_path, + )) + + return articles |
