diff --git a/src/templates/article.html b/src/templates/article.html index 68bbda8..afce02e 100644 --- a/src/templates/article.html +++ b/src/templates/article.html @@ -3,7 +3,7 @@ - {{meta.slug}} + {{slug}} @@ -21,6 +21,7 @@
+ {% if translations|length %}

Translations

@@ -34,7 +35,7 @@

{{t.preview}}
- +

@@ -42,6 +43,8 @@ {% endfor %}
+ {% endif %} + {% if children|length %}
@@ -53,9 +56,9 @@
-

{{c.meta.slug}}

+

{{c.slug}}

- +

diff --git a/stsg/build.py b/stsg/build.py index cebd1f1..6ec9cec 100644 --- a/stsg/build.py +++ b/stsg/build.py @@ -145,7 +145,7 @@ class ArticleTranslation: self.title = get_first_header_content(self.article_content, fallback="") 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["language"] = LANGUAGES[self.language_code] self.context["article_url"] = self.article.url @@ -166,11 +166,11 @@ class ArticleTranslation: 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.context: Dict[str, Any] = {} - self.context_meta = self.context["meta"] = {} + self.context_shared: Dict[str, Any] = {} # initializing the config values of the article config_file = self.directory / "index.toml" @@ -206,6 +206,7 @@ class Article: self.child_articles.append(Article( directory=c, location_in_tree=self.location_in_tree.copy(), + parent=self, )) 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())) def __init_context__(self): - self.context["url"] = self.url - self.context_meta["slug"] = self.slug + self.context_shared["url"] = self.url + 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) - self.context_meta["date"] = modified_at.strftime(config.formatting.datetime_format) - self.context_meta["iso_date"] = modified_at.isoformat() + self.context_shared["date"] = modified_at.strftime(config.formatting.datetime_format) + self.context_shared["iso_date"] = modified_at.isoformat() + + self.context.update(self.context_shared) # recursive context structures translation_list = self.context["translations"] = []