feat: hastly implementation of article cards
This commit is contained in:
parent
c7cd5e0601
commit
7db84492b5
@ -25,6 +25,12 @@
|
||||
<section class="section">
|
||||
<div class="content">
|
||||
{article_content}
|
||||
|
||||
<h1>Further Reading</h1>
|
||||
|
||||
<div class="row">
|
||||
{article_children_cards}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
<div class="card-content">
|
||||
<p class="title">{article_title} </p>
|
||||
<p class="content">
|
||||
{article_preview}
|
||||
<br />
|
||||
<time datetime="{article_datetime_iso}">{article_datetime}</time>
|
||||
</p>
|
||||
</div>
|
||||
|
@ -37,6 +37,7 @@ class Template:
|
||||
self.article: str = (self.folder / "article.html").read_text()
|
||||
self.overview: str = (self.folder / "overview.html").read_text()
|
||||
self.translation_card: str = (self.folder / "translation_card.html").read_text()
|
||||
self.article_card: str = (self.folder / "article_card.html").read_text()
|
||||
|
||||
|
||||
|
||||
@ -68,16 +69,28 @@ class ArticleTranslation:
|
||||
self.priority: int = _language_info.get("priority", 0)
|
||||
|
||||
self.title = get_first_header_content(self.article_content, fallback=self.language_name)
|
||||
|
||||
self.article_cards = ""
|
||||
|
||||
|
||||
def post_init(self):
|
||||
"""
|
||||
the initializing that takes place after the creation of the tree
|
||||
"""
|
||||
article_card_strings = []
|
||||
for child in self.article_overview.child_articles:
|
||||
if self.language_code in child.article_translations_map:
|
||||
article_card_strings.append(child.article_translations_map[self.language_code].get_article_card())
|
||||
|
||||
self.article_cards = "\n".join(article_card_strings)
|
||||
|
||||
|
||||
|
||||
def build(self):
|
||||
self.dist_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with Path(self.dist_path, "index.html").open("w") as f:
|
||||
f.write(self.get_article())
|
||||
|
||||
|
||||
def _get_values(self, return_foreign_articles: bool = True) -> Dict[str, str]:
|
||||
r = {
|
||||
"article_content": self.article_content,
|
||||
@ -91,6 +104,7 @@ class ArticleTranslation:
|
||||
"article_language_name": self.language_name,
|
||||
"article_language_code": self.language_code,
|
||||
"article_language_flag": self.language_flag,
|
||||
"article_children_cards": self.article_cards,
|
||||
}
|
||||
|
||||
if return_foreign_articles:
|
||||
@ -106,12 +120,13 @@ class ArticleTranslation:
|
||||
return res
|
||||
|
||||
def get_article(self) -> str:
|
||||
global TEMPLATE
|
||||
return replace_values(TEMPLATE.article, self._get_values())
|
||||
|
||||
def get_overview_card(self) -> str:
|
||||
global TEMPLATE
|
||||
def get_translation_card(self) -> str:
|
||||
return replace_values(TEMPLATE.translation_card, self._get_values())
|
||||
|
||||
def get_article_card(self) -> str:
|
||||
return replace_values(TEMPLATE.article_card, self._get_values())
|
||||
|
||||
|
||||
class ArticleOverview:
|
||||
@ -157,7 +172,11 @@ class ArticleOverview:
|
||||
|
||||
# the tree is built
|
||||
self.article_translations.sort(key=lambda a: a.priority, reverse=True)
|
||||
self.overview_cards = "\n".join(a.get_overview_card() for a in self.article_translations)
|
||||
self.translation_cards = "\n".join(a.get_translation_card() for a in self.article_translations)
|
||||
self.article_cards = "\n".join(c.get_article_card() for c in self.child_articles)
|
||||
|
||||
for at in self.article_translations:
|
||||
at.post_init()
|
||||
|
||||
logger.info("found %s at %s with the translations %s", self.slug, ".".join(list(self.location_in_tree)), ",".join(self.article_translations_map.keys()))
|
||||
|
||||
@ -181,7 +200,8 @@ class ArticleOverview:
|
||||
"article_datetime": self.article_written.strftime(config.formatting.datetime_format),
|
||||
"article_datetime_iso": self.article_written.isoformat(),
|
||||
"article_overview_url": self.url,
|
||||
"article_translation_cards": self.overview_cards,
|
||||
"article_translation_cards": self.translation_cards,
|
||||
"article_children_cards": self.article_cards,
|
||||
}
|
||||
|
||||
if return_foreign_articles:
|
||||
@ -200,6 +220,9 @@ class ArticleOverview:
|
||||
global TEMPLATE
|
||||
return replace_values(TEMPLATE.overview, self._get_values())
|
||||
|
||||
def get_article_card(self) -> str:
|
||||
return replace_values(TEMPLATE.article_card, self._get_values())
|
||||
|
||||
|
||||
# GLOBALS
|
||||
logger = logging.getLogger("stsg.build")
|
||||
|
Loading…
x
Reference in New Issue
Block a user