summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-03 12:56:09 +0200
committerDanilo M. <danix@danix.xyz>2026-05-03 12:56:09 +0200
commit220b9e054424569afc3298be04eeff6d7fa18381 (patch)
tree62cdb045252692301a3c27cb0492705e25eeb2d6
parentd821a186b485f395d83ab76ee73e4c21e7441a66 (diff)
downloadpublisher-220b9e054424569afc3298be04eeff6d7fa18381.tar.gz
publisher-220b9e054424569afc3298be04eeff6d7fa18381.zip
feat: add meta_type, meta_tags, meta_categories, meta_date properties to Article
-rw-r--r--core/models.py29
-rw-r--r--tests/test_models.py45
2 files changed, 74 insertions, 0 deletions
diff --git a/core/models.py b/core/models.py
index 3df2088..9a7cff5 100644
--- a/core/models.py
+++ b/core/models.py
@@ -13,3 +13,32 @@ class Article:
frontmatter: dict
has_translation: bool
translation_path: Path | None
+
+ @property
+ def draft(self) -> bool:
+ return bool(self.frontmatter.get("draft", False))
+
+ @property
+ def meta_type(self) -> str:
+ return str(self.frontmatter.get("type", ""))
+
+ @property
+ def meta_tags(self) -> str:
+ tags = self.frontmatter.get("tags", [])
+ if isinstance(tags, list):
+ return ", ".join(str(t) for t in tags)
+ return str(tags) if tags else ""
+
+ @property
+ def meta_categories(self) -> str:
+ cats = self.frontmatter.get("categories", [])
+ if isinstance(cats, list):
+ return ", ".join(str(c) for c in cats)
+ return str(cats) if cats else ""
+
+ @property
+ def meta_date(self) -> str:
+ raw = self.frontmatter.get("date", "")
+ if not raw:
+ return ""
+ return str(raw)[:10] # ISO date → "YYYY-MM-DD"
diff --git a/tests/test_models.py b/tests/test_models.py
index 858ce21..3d83653 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -34,3 +34,48 @@ def test_article_with_translation():
)
assert a.has_translation is True
assert a.translation_path is not None
+
+
+def test_article_draft_property():
+ fm = {"draft": True, "type": "Tech", "tags": ["linux"], "categories": ["DIY"], "date": "2024-01-15T10:00:00+00:00"}
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
+ assert a.draft is True
+
+
+def test_article_meta_type():
+ fm = {"type": "Tech"}
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
+ assert a.meta_type == "Tech"
+
+
+def test_article_meta_type_missing():
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter={}, has_translation=False, translation_path=None)
+ assert a.meta_type == ""
+
+
+def test_article_meta_tags():
+ fm = {"tags": ["linux", "python"]}
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
+ assert a.meta_tags == "linux, python"
+
+
+def test_article_meta_tags_empty():
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter={}, has_translation=False, translation_path=None)
+ assert a.meta_tags == ""
+
+
+def test_article_meta_categories():
+ fm = {"categories": ["DIY", "Tech"]}
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
+ assert a.meta_categories == "DIY, Tech"
+
+
+def test_article_meta_date():
+ fm = {"date": "2024-01-15T10:00:00+00:00"}
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter=fm, has_translation=False, translation_path=None)
+ assert a.meta_date == "2024-01-15"
+
+
+def test_article_meta_date_missing():
+ a = Article(slug="test", lang="it", path=Path("/tmp/test"), frontmatter={}, has_translation=False, translation_path=None)
+ assert a.meta_date == ""