From 823703d848e810ee1dbe00d5470c60302a59a422 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 3 May 2026 10:01:57 +0200 Subject: feat: article scanner with translation pair detection --- core/article_scanner.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 core/article_scanner.py (limited to 'core') 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 -- cgit v1.2.3