diff options
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 |
