From d3ff0029013ddadba3e9cc7d1806487d51de1e61 Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Thu, 22 May 2025 16:08:36 +0200 Subject: [PATCH] added breadcrumbs --- src/templates/article.html | 13 +++++++++++++ src/templates/article_translation.html | 13 +++++++++++++ stsg/build.py | 6 +++++- stsg/definitions.py | 2 ++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/templates/article.html b/src/templates/article.html index 106b1dd..a1bb30e 100644 --- a/src/templates/article.html +++ b/src/templates/article.html @@ -21,6 +21,19 @@ + {% if breadcrumbs|length %} + + + {% endif %} +
{% if translations|length %}
diff --git a/src/templates/article_translation.html b/src/templates/article_translation.html index 8052579..3552444 100644 --- a/src/templates/article_translation.html +++ b/src/templates/article_translation.html @@ -23,6 +23,19 @@
+ {% if breadcrumbs|length %} + + + {% endif %} +
diff --git a/stsg/build.py b/stsg/build.py index 7477473..99ffaeb 100644 --- a/stsg/build.py +++ b/stsg/build.py @@ -246,6 +246,7 @@ class ArticleTranslation: # get children self.context["children"] = self.article.child_articles.get_translated(self.language_code).context + self.context["breadcrumbs"] = ArticleList(self.article.article_path).get_translated(self.language_code).context def __init_content_context__(self): template = jinja2.Template(self.html_content) @@ -388,6 +389,7 @@ class Article: # recursive context structures self.context["translations"] = [c.context for c in self.article_translations_list] self.context["children"] = self.child_articles.context + self.context["breadcrumbs"] = [b.context for b in self.article_path] for lang, article in self.article_translations_map.items(): self.context[lang] = article.context @@ -448,6 +450,7 @@ def build(): tree.__init_context__() tree.__init_content_context__() + """ import json with Path("context.json").open("w") as f: json.dump(tree.context, f, indent=4) @@ -455,6 +458,7 @@ def build(): json.dump(CROSS_ARTICLE_CONTEXT, f, indent=4) with Path("t_cross_article_context.json").open("w") as f: json.dump(TRANSLATED_CROSS_ARTICLE_CONTEXT, f, indent=4) - + """ + logger.info("dumping page tree...") tree.build() diff --git a/stsg/definitions.py b/stsg/definitions.py index 838452f..8f2d4cd 100644 --- a/stsg/definitions.py +++ b/stsg/definitions.py @@ -20,6 +20,7 @@ class ArticleContext(TypedDict): translations: List[ArticleTranslationContext] children: List[ArticleContext] + breadcrumbs: List[ArticleContext] linked: List[ArticleContext] related: List[ArticleContext] @@ -50,6 +51,7 @@ class ArticleTranslationContext(TypedDict): config.fall_back_to_overview_in_translation = False """ children: List[Union[ArticleTranslationContext, ArticleContext]] + breadcrumbs: List[Union[ArticleTranslationContext, ArticleContext]] # you can't use these within the markdown text itself content: str