feat: move meta values to article
This commit is contained in:
parent
eb2edc3710
commit
44b651cace
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<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" />
|
||||
</head>
|
||||
<body>
|
||||
@ -21,6 +21,7 @@
|
||||
</nav>
|
||||
|
||||
<section class="section">
|
||||
{% if translations|length %}
|
||||
<div class="container content">
|
||||
<div class="column is-half is-offset-one-quarter">
|
||||
<h1>Translations</h1>
|
||||
@ -34,7 +35,7 @@
|
||||
<p class="content">
|
||||
{{t.preview}}
|
||||
<br />
|
||||
<time datetime="{{meta.iso_date}}">{{meta.date}}</time>
|
||||
<time datetime="{{iso_date}}">{{date}}</time>
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
@ -42,6 +43,8 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if children|length %}
|
||||
<div class="container content">
|
||||
@ -53,9 +56,9 @@
|
||||
<div class="card mb-4" >
|
||||
<a href="{{c.url}}" class="card mb-4" style="color: inherit; text-decoration: none;">
|
||||
<div class="card-content">
|
||||
<p class="title">{{c.meta.slug}} </p>
|
||||
<p class="title">{{c.slug}} </p>
|
||||
<p class="content">
|
||||
<time datetime="{{meta.iso_date}}">{{meta.date}}</time>
|
||||
<time datetime="{{iso_date}}">{{date}}</time>
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
|
@ -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"] = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user