summaryrefslogtreecommitdiffstats
path: root/core/models.py
blob: e7f0c361902361763c11d75ebbf1caa12809bda5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path

ARTICLE_TYPES = ["life", "photo", "link", "quote", "tech"]


@dataclass
class Article:
    slug: str
    lang: str          # "it" | "en"
    path: Path
    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"