feat: started cleaning up context
This commit is contained in:
parent
632f47e017
commit
036d5fb30a
@ -1,2 +1,2 @@
|
|||||||
name="stsg"
|
name="stsg"
|
||||||
datetime="2024-04-15 13:45:12.123456"
|
iso_date="2024-04-15 13:45:12.123456"
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
class config:
|
class config:
|
||||||
|
default_author = "anonymous"
|
||||||
|
|
||||||
class setup:
|
class setup:
|
||||||
source_directory = "src"
|
source_directory = "src"
|
||||||
dist_directory = "dist"
|
dist_directory = "dist"
|
||||||
|
@ -13,6 +13,7 @@ import jinja2
|
|||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
from .definitions import *
|
||||||
from . import config
|
from . import config
|
||||||
|
|
||||||
|
|
||||||
@ -127,12 +128,6 @@ def compile_cross_article_context(cross_article_context):
|
|||||||
cross_article_context["link"] = f'<a href="{url}">{title}</a>'
|
cross_article_context["link"] = f'<a href="{url}">{title}</a>'
|
||||||
|
|
||||||
|
|
||||||
class ArticleTranslationContext(TypedDict):
|
|
||||||
slug: str
|
|
||||||
name: str
|
|
||||||
datetime: str
|
|
||||||
author: str
|
|
||||||
url: str
|
|
||||||
|
|
||||||
|
|
||||||
class ArticleTranslation:
|
class ArticleTranslation:
|
||||||
@ -239,20 +234,6 @@ class ArticleTranslation:
|
|||||||
f.write(TEMPLATE["article_translation"].render(self.context))
|
f.write(TEMPLATE["article_translation"].render(self.context))
|
||||||
|
|
||||||
|
|
||||||
class ArticleConfig(TypedDict):
|
|
||||||
slug: str
|
|
||||||
name: str
|
|
||||||
datetime: str
|
|
||||||
author: str
|
|
||||||
|
|
||||||
|
|
||||||
class ArticleContext(TypedDict):
|
|
||||||
slug: str
|
|
||||||
name: str
|
|
||||||
datetime: str
|
|
||||||
author: str
|
|
||||||
url: str
|
|
||||||
|
|
||||||
class Article:
|
class Article:
|
||||||
directory: Path
|
directory: Path
|
||||||
|
|
||||||
@ -327,15 +308,29 @@ class Article:
|
|||||||
|
|
||||||
logger.info("found %s at %s with the translations %s", self.slug, ".".join(list(self.slug_path)), ",".join(self.article_translations_map.keys()))
|
logger.info("found %s at %s with the translations %s", self.slug, ".".join(list(self.slug_path)), ",".join(self.article_translations_map.keys()))
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def modified_at(self) -> datetime:
|
||||||
|
if "iso_date" in self.config:
|
||||||
|
return datetime.fromisoformat(self.config["iso_date"])
|
||||||
|
|
||||||
|
"""
|
||||||
|
TODO
|
||||||
|
scann every article file and use the youngest article file
|
||||||
|
"""
|
||||||
|
|
||||||
|
return datetime.fromtimestamp(self.directory.stat().st_mtime)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def author(self) -> str:
|
||||||
|
return self.config.get("author", config.default_author)
|
||||||
|
|
||||||
def __init_context__(self):
|
def __init_context__(self):
|
||||||
self.context_shared["url"] = self.url
|
self.context["slug"] = self.slug
|
||||||
self.context_shared["slug"] = self.slug
|
self.context["name"] = self.name
|
||||||
|
self.context["url"] = self.url
|
||||||
modified_at = datetime.fromisoformat(self.config["datetime"]) if "datetime" in self.config else datetime.fromtimestamp(self.directory.stat().st_mtime)
|
self.context["date"] = self.modified_at.strftime(config.formatting.datetime_format)
|
||||||
self.context_shared["date"] = modified_at.strftime(config.formatting.datetime_format)
|
self.context["iso_date"] = self.modified_at.isoformat()
|
||||||
self.context_shared["iso_date"] = modified_at.isoformat()
|
self.context["author"] = self.author
|
||||||
|
|
||||||
self.context.update(self.context_shared)
|
|
||||||
|
|
||||||
self.cross_article_context.update(self.context_shared)
|
self.cross_article_context.update(self.context_shared)
|
||||||
self.cross_article_context["title"] = self.context_shared["slug"]
|
self.cross_article_context["title"] = self.context_shared["slug"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user