feat: move meta values to article

This commit is contained in:
Hazel 2025-04-16 16:39:06 +02:00
parent eb2edc3710
commit 44b651cace
2 changed files with 17 additions and 11 deletions

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{meta.slug}}</title> <title>{{slug}}</title>
<link rel="stylesheet" href="/static/bulma.min.css" /> <link rel="stylesheet" href="/static/bulma.min.css" />
</head> </head>
<body> <body>
@ -21,6 +21,7 @@
</nav> </nav>
<section class="section"> <section class="section">
{% if translations|length %}
<div class="container content"> <div class="container content">
<div class="column is-half is-offset-one-quarter"> <div class="column is-half is-offset-one-quarter">
<h1>Translations</h1> <h1>Translations</h1>
@ -34,7 +35,7 @@
<p class="content"> <p class="content">
{{t.preview}} {{t.preview}}
<br /> <br />
<time datetime="{{meta.iso_date}}">{{meta.date}}</time> <time datetime="{{iso_date}}">{{date}}</time>
</p> </p>
</div> </div>
</a> </a>
@ -42,6 +43,8 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% endif %}
{% if children|length %} {% if children|length %}
<div class="container content"> <div class="container content">
@ -53,9 +56,9 @@
<div class="card mb-4" > <div class="card mb-4" >
<a href="{{c.url}}" class="card mb-4" style="color: inherit; text-decoration: none;"> <a href="{{c.url}}" class="card mb-4" style="color: inherit; text-decoration: none;">
<div class="card-content"> <div class="card-content">
<p class="title">{{c.meta.slug}} </p> <p class="title">{{c.slug}} </p>
<p class="content"> <p class="content">
<time datetime="{{meta.iso_date}}">{{meta.date}}</time> <time datetime="{{iso_date}}">{{date}}</time>
</p> </p>
</div> </div>
</a> </a>

View File

@ -145,7 +145,7 @@ class ArticleTranslation:
self.title = get_first_header_content(self.article_content, fallback="") self.title = get_first_header_content(self.article_content, fallback="")
def __init_context__(self): def __init_context__(self):
self.context["meta"] = self.article.context_meta self.context["meta"] = self.article.context_shared
self.context["url"] = self.url self.context["url"] = self.url
self.context["language"] = LANGUAGES[self.language_code] self.context["language"] = LANGUAGES[self.language_code]
self.context["article_url"] = self.article.url self.context["article_url"] = self.article.url
@ -166,11 +166,11 @@ class ArticleTranslation:
class Article: class Article:
def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None, is_root: bool = False): def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None, is_root: bool = False, parent: Optional[Article] = None):
self.directory = directory self.directory = directory
self.context: Dict[str, Any] = {} self.context: Dict[str, Any] = {}
self.context_meta = self.context["meta"] = {} self.context_shared: Dict[str, Any] = {}
# initializing the config values of the article # initializing the config values of the article
config_file = self.directory / "index.toml" config_file = self.directory / "index.toml"
@ -206,6 +206,7 @@ class Article:
self.child_articles.append(Article( self.child_articles.append(Article(
directory=c, directory=c,
location_in_tree=self.location_in_tree.copy(), location_in_tree=self.location_in_tree.copy(),
parent=self,
)) ))
self.article_translations_list.sort(key=lambda a: a.priority, reverse=True) self.article_translations_list.sort(key=lambda a: a.priority, reverse=True)
@ -213,12 +214,14 @@ class Article:
logger.info("found %s at %s with the translations %s", self.slug, ".".join(list(self.location_in_tree)), ",".join(self.article_translations_map.keys())) logger.info("found %s at %s with the translations %s", self.slug, ".".join(list(self.location_in_tree)), ",".join(self.article_translations_map.keys()))
def __init_context__(self): def __init_context__(self):
self.context["url"] = self.url self.context_shared["url"] = self.url
self.context_meta["slug"] = self.slug self.context_shared["slug"] = self.slug
modified_at = datetime.fromisoformat(self.config["datetime"]) if "datetime" in self.config else datetime.fromtimestamp(self.directory.stat().st_mtime) modified_at = datetime.fromisoformat(self.config["datetime"]) if "datetime" in self.config else datetime.fromtimestamp(self.directory.stat().st_mtime)
self.context_meta["date"] = modified_at.strftime(config.formatting.datetime_format) self.context_shared["date"] = modified_at.strftime(config.formatting.datetime_format)
self.context_meta["iso_date"] = modified_at.isoformat() self.context_shared["iso_date"] = modified_at.isoformat()
self.context.update(self.context_shared)
# recursive context structures # recursive context structures
translation_list = self.context["translations"] = [] translation_list = self.context["translations"] = []