Compare commits

8 Commits

4 changed files with 33 additions and 64 deletions

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <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" /> <link rel="stylesheet" href="/static/bulma.min.css" />
</head> </head>
<body> <body>
@@ -21,20 +21,21 @@
</nav> </nav>
<section class="section"> <section class="section">
{% if translations|length %}
<div class="container content"> <div class="container content">
<div class="column is-half is-offset-one-quarter"> <div class="column is-half is-offset-one-quarter">
<h1>Translations</h1> <h1>Translations</h1>
</div> </div>
<div class="column is-half is-offset-one-quarter"> <div class="column is-half is-offset-one-quarter">
{% for t in translations %} {% for t in translations %}
<div class="card mb-4" lang="{[t.language.code]}"> <div class="card mb-4" lang="{{t.language.code}}">
<a href="{{t.url}}" hreflang="{[t.language.code]}" class="card mb-4" style="color: inherit; text-decoration: none;"> <a href="{{t.url}}" hreflang="{{t.language.code}}" class="card mb-4" style="color: inherit; text-decoration: none;">
<div class="card-content"> <div class="card-content">
<p class="title">{{t.language.flag}} {{t.title}} </p> <p class="title">{{t.language.flag}} {{t.title}} </p>
<p class="content"> <p class="content">
{{t.preview}} {{t.preview}}
<br /> <br />
<time datetime="{{meta.iso_date}}">{{meta.date}}</time> <time datetime="{{iso_date}}">{{date}}</time>
</p> </p>
</div> </div>
</a> </a>
@@ -42,15 +43,30 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% endif %}
{% if children|length %}
<div class="container content"> <div class="container content">
<div class="column is-half is-offset-one-quarter"> <div class="column is-half is-offset-one-quarter">
<h1>Child Articles</h1> <h1>Child Articles</h1>
</div> </div>
<div class="column is-half is-offset-one-quarter"> <div class="column is-half is-offset-one-quarter">
{article_children_cards} {% for c in children %}
<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.slug}} </p>
<p class="content">
<time datetime="{{iso_date}}">{{date}}</time>
</p>
</div>
</a>
</div>
{% endfor %}
</div> </div>
</div> </div>
{% endif %}
</section> </section>
<!-- Footer --> <!-- Footer -->

View File

@@ -1,12 +0,0 @@
<div class="card mb-4">
<a href="{article_url}" class="card mb-4" style="color: inherit; text-decoration: none;">
<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>
</a>
</div>

View File

@@ -1,12 +0,0 @@
<div class="card mb-4" lang="{article_language_code}">
<a href="{article_url}" hreflang="{article_language_code}" class="card mb-4" style="color: inherit; text-decoration: none;">
<div class="card-content">
<p class="title">{article_language_flag} {article_title} </p>
<p class="content">
{article_preview}
<br />
<time datetime="{article_datetime_iso}">{article_datetime}</time>
</p>
</div>
</a>
</div>

View File

@@ -145,7 +145,7 @@ class ArticleTranslation:
self.title = get_first_header_content(self.article_content, fallback="") self.title = get_first_header_content(self.article_content, fallback="")
def __init_context__(self): 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["url"] = self.url
self.context["language"] = LANGUAGES[self.language_code] self.context["language"] = LANGUAGES[self.language_code]
self.context["article_url"] = self.article.url self.context["article_url"] = self.article.url
@@ -166,11 +166,13 @@ class ArticleTranslation:
class Article: 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.directory = directory
self.context: Dict[str, Any] = {} self.context: Dict[str, Any] = {}
self.context_meta = self.context["meta"] = {} self.context_shared: Dict[str, Any] = {}
if parent is not None:
self.context["parent"] = parent.context_shared
# initializing the config values of the article # initializing the config values of the article
config_file = self.directory / "index.toml" config_file = self.directory / "index.toml"
@@ -206,6 +208,7 @@ class Article:
self.child_articles.append(Article( self.child_articles.append(Article(
directory=c, directory=c,
location_in_tree=self.location_in_tree.copy(), location_in_tree=self.location_in_tree.copy(),
parent=self,
)) ))
self.article_translations_list.sort(key=lambda a: a.priority, reverse=True) self.article_translations_list.sort(key=lambda a: a.priority, reverse=True)
@@ -213,12 +216,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())) 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): def __init_context__(self):
self.context["url"] = self.url self.context_shared["url"] = self.url
self.context_meta["slug"] = self.slug 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) 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_shared["date"] = modified_at.strftime(config.formatting.datetime_format)
self.context_meta["iso_date"] = modified_at.isoformat() self.context_shared["iso_date"] = modified_at.isoformat()
self.context.update(self.context_shared)
# recursive context structures # recursive context structures
translation_list = self.context["translations"] = [] translation_list = self.context["translations"] = []
@@ -249,32 +254,6 @@ class Article:
for ac in self.child_articles: for ac in self.child_articles:
ac.build() ac.build()
def _get_values(self, return_foreign_articles: bool = True) -> Dict[str, str]:
r = {
"article_overview_url": self.url,
"article_translation_cards": self.translation_cards,
"article_children_cards": self.article_cards,
}
if return_foreign_articles:
r.update(ARTICLE_REFERENCE_VALUES[""])
return r
def get_article_values(self) -> Dict[str, str]:
res = {}
for key, value in self._get_values(return_foreign_articles=False).items():
res[key + ":" + self.slug] = value
return res
def get_overview(self) -> str:
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 # GLOBALS
logger = logging.getLogger("stsg.build") logger = logging.getLogger("stsg.build")
@@ -290,8 +269,6 @@ def build():
logger.info("building page tree...") logger.info("building page tree...")
tree = Article(directory=Path(config.setup.source_directory, "articles"), is_root=True) tree = Article(directory=Path(config.setup.source_directory, "articles"), is_root=True)
print(ARTICLE_LAKE.keys())
logger.info("compiling tree context...") logger.info("compiling tree context...")
tree.__init_context__() tree.__init_context__()