feat: added linked article to context
This commit is contained in:
parent
693022ac23
commit
e3fe49bed7
@ -4,7 +4,7 @@ dependencies = [
|
|||||||
"watchdog~=6.0.0",
|
"watchdog~=6.0.0",
|
||||||
"markdown~=3.3.6",
|
"markdown~=3.3.6",
|
||||||
"bs4~=0.0.2",
|
"bs4~=0.0.2",
|
||||||
"toml~0.10.2",
|
"toml~=0.10.2",
|
||||||
"jinja2~=3.1.6",
|
"jinja2~=3.1.6",
|
||||||
]
|
]
|
||||||
dynamic = []
|
dynamic = []
|
||||||
|
@ -30,6 +30,34 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
{% if linked|length %}
|
||||||
|
<section class="section">
|
||||||
|
<div class="content">
|
||||||
|
<div class="columns is-multiline">
|
||||||
|
{% for c in linked %}
|
||||||
|
<div class="column is-half">
|
||||||
|
<div class="card mb-4" >
|
||||||
|
<a href="{{c.url}}" hreflang="{{c.language.code}}" class="card mb-4" style="color: inherit; text-decoration: none;">
|
||||||
|
<div class="card-content">
|
||||||
|
<p class="title">{{c.title}}</p>
|
||||||
|
<hr />
|
||||||
|
<p class="content">
|
||||||
|
{{c.preview}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-footer">
|
||||||
|
<time class="card-footer-item" datetime="{{c.meta.iso_date}}">{{c.meta.date}}</time>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if children|length %}
|
{% if children|length %}
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@ -178,13 +178,25 @@ class ArticleTranslation:
|
|||||||
if self.language_code in c.article_translations_map
|
if self.language_code in c.article_translations_map
|
||||||
]
|
]
|
||||||
|
|
||||||
|
self.linked_context = self.context["linked"] = []
|
||||||
|
|
||||||
def __init_content_context__(self):
|
def __init_content_context__(self):
|
||||||
template = jinja2.Template(self.html_content)
|
template = jinja2.Template(self.html_content)
|
||||||
|
template.environment.accessed_keys = []
|
||||||
|
template.environment.context_class = ContextDict
|
||||||
|
|
||||||
self.html_content = template.render({
|
self.html_content = template.render({
|
||||||
**CROSS_ARTICLE_CONTEXT,
|
**CROSS_ARTICLE_CONTEXT,
|
||||||
**TRANSLATED_CROSS_ARTICLE_CONTEXT[self.language_code],
|
**TRANSLATED_CROSS_ARTICLE_CONTEXT[self.language_code],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
template.environment.context_class = jinja2.runtime.Context
|
||||||
|
accessed_keys = template.environment.accessed_keys
|
||||||
|
for key in accessed_keys:
|
||||||
|
a = ARTICLE_LAKE[key]
|
||||||
|
if self.language_code in a.article_translations_map:
|
||||||
|
self.linked_context.append(a.article_translations_map[self.language_code].context)
|
||||||
|
|
||||||
self.context["content"] = self.html_content
|
self.context["content"] = self.html_content
|
||||||
self.context["preview"] = get_preview_text(html_string=self.html_content)
|
self.context["preview"] = get_preview_text(html_string=self.html_content)
|
||||||
|
|
||||||
@ -297,6 +309,13 @@ class Article:
|
|||||||
ac.build()
|
ac.build()
|
||||||
|
|
||||||
|
|
||||||
|
class ContextDict(jinja2.runtime.Context):
|
||||||
|
def resolve_or_missing(self, key: str) -> Any:
|
||||||
|
self.environment.accessed_keys.append(key)
|
||||||
|
return super().resolve_or_missing(key)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# GLOBALS
|
# GLOBALS
|
||||||
logger = logging.getLogger("stsg.build")
|
logger = logging.getLogger("stsg.build")
|
||||||
CROSS_ARTICLE_CONTEXT: Dict[str, Dict[str, Any]] = {}
|
CROSS_ARTICLE_CONTEXT: Dict[str, Dict[str, Any]] = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user