Compare commits
9 Commits
b50833f19f
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b030b24f4 | |||
| 44b651cace | |||
| eb2edc3710 | |||
| f63497090b | |||
| 215142dee4 | |||
| e391f64cc5 | |||
| 4216d153fd | |||
| 9241ecfee8 | |||
| 4bc7a6d980 |
@@ -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,20 +21,21 @@
|
||||
</nav>
|
||||
|
||||
<section class="section">
|
||||
{% if translations|length %}
|
||||
<div class="container content">
|
||||
<div class="column is-half is-offset-one-quarter">
|
||||
<h1>Translations</h1>
|
||||
</div>
|
||||
<div class="column is-half is-offset-one-quarter">
|
||||
{% for t in translations %}
|
||||
<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;">
|
||||
<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;">
|
||||
<div class="card-content">
|
||||
<p class="title">{{t.language.flag}} {{t.title}} </p>
|
||||
<p class="content">
|
||||
{{t.preview}}
|
||||
<br />
|
||||
<time datetime="{{meta.iso_date}}">{{meta.date}}</time>
|
||||
<time datetime="{{iso_date}}">{{date}}</time>
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
@@ -42,15 +43,30 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if children|length %}
|
||||
<div class="container content">
|
||||
<div class="column is-half is-offset-one-quarter">
|
||||
<h1>Child Articles</h1>
|
||||
</div>
|
||||
<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>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
<!-- Footer -->
|
||||
|
||||
@@ -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>
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>{article_language_flag} {article_title}</title>
|
||||
<title>{{language.flag}} {{title}}</title>
|
||||
<link rel="stylesheet" href="/static/bulma.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
@@ -14,9 +14,9 @@
|
||||
aria-label="main navigation"
|
||||
>
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="{article_overview_url}">
|
||||
<strong>{article_language_flag} {article_title}</strong>
|
||||
<time datetime="{article_datetime_iso}">{article_datetime}</time>
|
||||
<a class="navbar-item" href="{{article_url}}">
|
||||
<strong>{{language.flag}} {{title}}</strong>
|
||||
<time datetime="{{meta.iso_date}}">{{meta.date}}</time>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -24,13 +24,7 @@
|
||||
<!-- Main Content -->
|
||||
<section class="section">
|
||||
<div class="content">
|
||||
{article_content}
|
||||
|
||||
<h1>Further Reading</h1>
|
||||
|
||||
<div class="row">
|
||||
{article_children_cards}
|
||||
</div>
|
||||
{{content}}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -145,9 +145,10 @@ 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
|
||||
|
||||
html_content = self.file.read_text()
|
||||
if self.file.suffix == ".md":
|
||||
@@ -165,11 +166,13 @@ 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] = {}
|
||||
if parent is not None:
|
||||
self.context["parent"] = parent.context_shared
|
||||
|
||||
# initializing the config values of the article
|
||||
config_file = self.directory / "index.toml"
|
||||
@@ -205,6 +208,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)
|
||||
@@ -212,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()))
|
||||
|
||||
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"] = []
|
||||
@@ -248,32 +254,6 @@ class Article:
|
||||
for ac in self.child_articles:
|
||||
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
|
||||
logger = logging.getLogger("stsg.build")
|
||||
@@ -289,8 +269,6 @@ def build():
|
||||
logger.info("building page tree...")
|
||||
tree = Article(directory=Path(config.setup.source_directory, "articles"), is_root=True)
|
||||
|
||||
print(ARTICLE_LAKE.keys())
|
||||
|
||||
logger.info("compiling tree context...")
|
||||
tree.__init_context__()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user