Compare commits
36 Commits
d412d983bd
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b030b24f4 | |||
| 44b651cace | |||
| eb2edc3710 | |||
| f63497090b | |||
| 215142dee4 | |||
| e391f64cc5 | |||
| 4216d153fd | |||
| 9241ecfee8 | |||
| 4bc7a6d980 | |||
| b50833f19f | |||
| f5cccc30dc | |||
| 8a8f02c5bd | |||
| 292d71edc5 | |||
| c9fb8fda93 | |||
| 1fae03e70b | |||
| 6ed94db8cf | |||
| 02a7c29dba | |||
| cf8e2955c2 | |||
| 7aa06b7f83 | |||
| f7a690405b | |||
| 93ea11cd0e | |||
| 263281df3c | |||
|
|
b953933e6f | ||
| 7db84492b5 | |||
| c7cd5e0601 | |||
| c05f8fad35 | |||
| b9c7535812 | |||
| cdcd3bce1f | |||
| 6eb02cc95f | |||
| 2454d26d6b | |||
| 8054a4a983 | |||
| afefce0a11 | |||
| 334c82d098 | |||
| ddd536c958 | |||
| ae5ba0d044 | |||
| 83133218a4 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -173,4 +173,5 @@ cython_debug/
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
dist
|
||||
dist
|
||||
context.json
|
||||
@@ -4,7 +4,8 @@ dependencies = [
|
||||
"watchdog~=6.0.0",
|
||||
"markdown~=3.3.6",
|
||||
"bs4~=0.0.2",
|
||||
"toml~0.10.2,"
|
||||
"toml~0.10.2",
|
||||
"jinja2~=3.1.6",
|
||||
]
|
||||
dynamic = []
|
||||
authors = []
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{article_language_code}">
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>{article_language_flag} {article_title}</title>
|
||||
<title>{{slug}}</title>
|
||||
<link rel="stylesheet" href="/static/bulma.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
@@ -14,17 +14,59 @@
|
||||
aria-label="main navigation"
|
||||
>
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="{article_overview_url}">
|
||||
<strong>{article_language_flag} {article_title}</strong>
|
||||
<a class="navbar-item" href="#">
|
||||
<strong>Static Translated Site Generator</strong>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Main Content -->
|
||||
<section class="section">
|
||||
<div class="content">
|
||||
{article_content}
|
||||
{% 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-content">
|
||||
<p class="title">{{t.language.flag}} {{t.title}} </p>
|
||||
<p class="content">
|
||||
{{t.preview}}
|
||||
<br />
|
||||
<time datetime="{{iso_date}}">{{date}}</time>
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% 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">
|
||||
{% 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 -->
|
||||
@@ -34,4 +76,23 @@
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const userLang = navigator.language || navigator.userLanguage;
|
||||
|
||||
// Normalize and check if the language is not English or German
|
||||
if (!["en", "de", "de-DE"].includes(userLang)) {
|
||||
// Try to find a matching card by language attribute
|
||||
const cardToMove =
|
||||
document.querySelector(`.card[lang^="${userLang.replace("_", "-").toLowerCase()}"]`) ||
|
||||
document.querySelector(`.card[lang^="${userLang.split("-")[0]}"]`);
|
||||
|
||||
if (cardToMove) {
|
||||
const container = cardToMove.parentNode;
|
||||
container.insertBefore(cardToMove, container.firstChild);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
|
||||
38
src/templates/article_translation.html
Normal file
38
src/templates/article_translation.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{article_language_code}">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>{{language.flag}} {{title}}</title>
|
||||
<link rel="stylesheet" href="/static/bulma.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header (Navbar) -->
|
||||
<nav
|
||||
class="navbar is-primary"
|
||||
role="navigation"
|
||||
aria-label="main navigation"
|
||||
>
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="{{article_url}}">
|
||||
<strong>{{language.flag}} {{title}}</strong>
|
||||
<time datetime="{{meta.iso_date}}">{{meta.date}}</time>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Main Content -->
|
||||
<section class="section">
|
||||
<div class="content">
|
||||
{{content}}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="footer">
|
||||
<div class="content has-text-centered">
|
||||
<p><strong>STSG</strong> by Hazel. © 2025</p>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,55 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>{article_name}</title>
|
||||
<link rel="stylesheet" href="/static/bulma.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
<!-- Header (Navbar) -->
|
||||
<nav
|
||||
class="navbar is-primary"
|
||||
role="navigation"
|
||||
aria-label="main navigation"
|
||||
>
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="#">
|
||||
<strong>Static Translated Site Generator</strong>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div class="column is-half is-offset-one-quarter">{article_overview_cards}</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="footer">
|
||||
<div class="content has-text-centered">
|
||||
<p><strong>STSG</strong> by Hazel. © 2025</p>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const userLang = navigator.language || navigator.userLanguage;
|
||||
|
||||
// Normalize and check if the language is not English or German
|
||||
if (!["en", "de", "de-DE"].includes(userLang)) {
|
||||
// Try to find a matching card by language attribute
|
||||
const cardToMove =
|
||||
document.querySelector(`.card[lang^="${userLang.replace("_", "-").toLowerCase()}"]`) ||
|
||||
document.querySelector(`.card[lang^="${userLang.split("-")[0]}"]`);
|
||||
|
||||
if (cardToMove) {
|
||||
const container = cardToMove.parentNode;
|
||||
container.insertBefore(cardToMove, container.firstChild);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
@@ -1,8 +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}</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
303
stsg/build.py
303
stsg/build.py
@@ -4,9 +4,12 @@ import shutil
|
||||
from pathlib import Path
|
||||
import os
|
||||
import markdown
|
||||
from typing import Optional, Union, Dict, Generator, List, DefaultDict
|
||||
from typing import Optional, Union, Dict, Generator, List, DefaultDict, Any
|
||||
from bs4 import BeautifulSoup
|
||||
from collections import defaultdict
|
||||
import toml
|
||||
from datetime import datetime
|
||||
import jinja2
|
||||
|
||||
from . import config
|
||||
|
||||
@@ -28,166 +31,233 @@ def get_first_header_content(content, fallback: str = ""):
|
||||
return fallback
|
||||
|
||||
|
||||
class Template:
|
||||
def shorten_text_and_clean(html_string, max_length=config.formatting.article_preview_length):
|
||||
soup = BeautifulSoup(html_string, 'html.parser')
|
||||
|
||||
# Keep track of total characters added
|
||||
total_chars = 0
|
||||
finished = False
|
||||
|
||||
# Function to recursively trim and clean text
|
||||
def process_element(element):
|
||||
nonlocal total_chars, finished
|
||||
|
||||
for child in list(element.children):
|
||||
if finished:
|
||||
child.extract()
|
||||
continue
|
||||
|
||||
if isinstance(child, str):
|
||||
remaining = max_length - total_chars
|
||||
if remaining <= 0:
|
||||
child.extract()
|
||||
finished = True
|
||||
elif len(child) > remaining:
|
||||
child.replace_with(child[:remaining] + '...')
|
||||
total_chars = max_length
|
||||
finished = True
|
||||
else:
|
||||
total_chars += len(child)
|
||||
elif hasattr(child, 'children'):
|
||||
process_element(child)
|
||||
# Remove empty tags
|
||||
if not child.text.strip():
|
||||
child.decompose()
|
||||
|
||||
process_element(soup)
|
||||
|
||||
return str(soup)
|
||||
|
||||
|
||||
def stem_to_language_code(stem: str) -> str:
|
||||
language_code = stem.lower().replace("-", "_")
|
||||
|
||||
if language_code in config.languages:
|
||||
return language_code
|
||||
|
||||
language_code = language_code.split("_")[0]
|
||||
if language_code in config.languages:
|
||||
return language_code
|
||||
|
||||
logger.error("Didn't recognize %s as a valid language code, add it to the config, or fix your structure.", stem)
|
||||
exit(1)
|
||||
|
||||
|
||||
|
||||
class TemplateDict(dict):
|
||||
def __init__(self, folder: Path):
|
||||
self.folder = folder
|
||||
super().__init__()
|
||||
|
||||
self.article: str = (self.folder / "article.html").read_text()
|
||||
self.overview: str = (self.folder / "overview.html").read_text()
|
||||
self.overview_card: str = (self.folder / "overview_card.html").read_text()
|
||||
def __missing__(self, name: str) -> jinja2.Template:
|
||||
f = self.folder / (name + ".html")
|
||||
if not f.exists():
|
||||
logger.error("no template with the name %s exists", name)
|
||||
exit(1)
|
||||
|
||||
t = jinja2.Template(f.read_text())
|
||||
self[name] = t
|
||||
return t
|
||||
|
||||
TEMPLATE: Dict[str, jinja2.Template] = TemplateDict(Path(config.setup.source_directory, "templates"))
|
||||
|
||||
class LanguageDict(dict):
|
||||
def __missing__(self, key: str):
|
||||
if key not in config.languages:
|
||||
raise KeyError(key)
|
||||
|
||||
lang_dict = config.languages[key]
|
||||
lang_dict["priority"] = lang_dict.get("priority", 0)
|
||||
|
||||
elements = key.split("_")
|
||||
if len(elements) > 1:
|
||||
elements[-1] = elements[-1].upper()
|
||||
lang_dict["code"] = "-".join(elements)
|
||||
|
||||
return lang_dict
|
||||
|
||||
LANGUAGES = LanguageDict()
|
||||
|
||||
|
||||
class ArticleTranslation:
|
||||
def __init__(self, file: Path, article_overview: ArticleOverview):
|
||||
def __init__(self, file: Path, article: Article):
|
||||
self.file = file
|
||||
self.article_overview = article_overview
|
||||
self.language_code = self.file.stem
|
||||
self.article = article
|
||||
|
||||
self.article_content = self.file.read_text()
|
||||
if self.file.suffix == ".md":
|
||||
self.article_content = markdown.markdown(self.article_content)
|
||||
self.context: Dict[str, Any] = {}
|
||||
|
||||
self.location_in_tree = [self.language_code, *self.article_overview.location_in_tree]
|
||||
# initializing the location of the article translation
|
||||
self.language_code = stem_to_language_code(self.file.stem)
|
||||
self.location_in_tree = [self.language_code, *self.article.location_in_tree]
|
||||
self.url = "/" + "/".join(self.location_in_tree)
|
||||
self.dist_path = Path(config.setup.dist_directory, *self.location_in_tree)
|
||||
|
||||
_language_info = config.languages[config.formatting.fallback_language]
|
||||
parsed_language_code = self.language_code.lower().replace("-", "_")
|
||||
if parsed_language_code in config.languages:
|
||||
_language_info = config.languages[parsed_language_code]
|
||||
elif parsed_language_code.split("_")[0] in config.languages:
|
||||
_language_info = config.languages[parsed_language_code.split("_")[0]]
|
||||
self.priority = LANGUAGES[self.language_code]["priority"]
|
||||
self.real_language_code = LANGUAGES[self.language_code]["code"]
|
||||
|
||||
self.language_name: str = _language_info["native_name"]
|
||||
self.language_flag: str = _language_info["flag"]
|
||||
self.priority: int = _language_info.get("priority", 0)
|
||||
# TODO remove
|
||||
self.article_content = self.file.read_text()
|
||||
self.article_preview = self.article_content[:config.formatting.article_preview_length] + "..."
|
||||
if self.file.suffix == ".md":
|
||||
self.article_content = markdown.markdown(self.article_content)
|
||||
self.article_preview = markdown.markdown(self.article_preview)
|
||||
|
||||
self.title = get_first_header_content(self.article_content, fallback=self.language_name)
|
||||
self.title = get_first_header_content(self.article_content, fallback="")
|
||||
|
||||
def __init_context__(self):
|
||||
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":
|
||||
html_content = markdown.markdown(html_content)
|
||||
|
||||
self.context["title"] = get_first_header_content(html_content, fallback=LANGUAGES[self.language_code]["native_name"])
|
||||
self.context["content"] = html_content
|
||||
self.context["preview"] = shorten_text_and_clean(html_string=html_content)
|
||||
|
||||
|
||||
def build(self):
|
||||
self.dist_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with Path(self.dist_path, "index.html").open("w") as f:
|
||||
f.write(self.get_article())
|
||||
f.write(TEMPLATE["article_translation"].render(self.context))
|
||||
|
||||
|
||||
def _get_values(self, return_foreign_articles: bool = True) -> Dict[str, str]:
|
||||
r = {
|
||||
"article_content": self.article_content,
|
||||
"article_preview": self.article_content[:config.formatting.article_preview_length] + "...",
|
||||
"article_url": self.url,
|
||||
"article_overview_url": self.article_overview.url,
|
||||
"article_slug": self.article_overview.slug,
|
||||
"article_title": self.title,
|
||||
"article_language_name": self.language_name,
|
||||
"article_language_code": self.language_code,
|
||||
"article_language_flag": self.language_flag,
|
||||
}
|
||||
|
||||
if return_foreign_articles:
|
||||
r.update(ARTICLE_REFERENCE_VALUES[self.language_code])
|
||||
|
||||
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.article_overview.slug] = value
|
||||
|
||||
return res
|
||||
|
||||
def get_article(self) -> str:
|
||||
global TEMPLATE
|
||||
return replace_values(TEMPLATE.article, self._get_values())
|
||||
|
||||
def get_overview_card(self) -> str:
|
||||
global TEMPLATE
|
||||
return replace_values(TEMPLATE.overview_card, self._get_values())
|
||||
|
||||
|
||||
class ArticleOverview:
|
||||
def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None):
|
||||
class Article:
|
||||
def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None, is_root: bool = False, parent: Optional[Article] = None):
|
||||
self.directory = directory
|
||||
self.slug = self.directory.name
|
||||
|
||||
self.article_written = self.directory.stat().st_mtime
|
||||
self.context: Dict[str, Any] = {}
|
||||
self.context_shared: Dict[str, Any] = {}
|
||||
if parent is not None:
|
||||
self.context["parent"] = parent.context_shared
|
||||
|
||||
self.location_in_tree: List[str] = location_in_tree or []
|
||||
self.location_in_tree.append(self.slug)
|
||||
self.url = "/" + "/".join(self.location_in_tree)
|
||||
self.dist_path = Path(config.setup.dist_directory, *self.location_in_tree)
|
||||
# initializing the config values of the article
|
||||
config_file = self.directory / "index.toml"
|
||||
self.config = toml.load(config_file) if config_file.exists() else {}
|
||||
|
||||
# initializing the location and slug of the article
|
||||
self.slug = self.config.get("name", self.directory.name)
|
||||
if self.slug in ARTICLE_LAKE:
|
||||
logger.error("two articles have the same name at %s and %r", ARTICLE_LAKE[self.slug].directory, self.directory)
|
||||
exit(1)
|
||||
ARTICLE_LAKE[self.slug] = self
|
||||
|
||||
self.child_articles: List[ArticleOverview] = []
|
||||
self.article_translations: List[ArticleTranslation] = []
|
||||
self.location_in_tree: List[str] = location_in_tree or []
|
||||
if not is_root:
|
||||
self.location_in_tree.append(self.slug)
|
||||
self.url = "/" + "/".join(self.location_in_tree)
|
||||
self.dist_path = Path(config.setup.dist_directory, *self.location_in_tree)
|
||||
|
||||
# build the tree
|
||||
self.child_articles: List[Article] = []
|
||||
self.article_translations_list: List[ArticleTranslation] = []
|
||||
self.article_translations_map: Dict[str, ArticleTranslation] = {}
|
||||
|
||||
for c in self.directory.iterdir():
|
||||
if c.name == "index.toml":
|
||||
continue
|
||||
|
||||
if c.is_file():
|
||||
at = ArticleTranslation(c, self)
|
||||
self.article_translations.append(at)
|
||||
self.article_translations_list.append(at)
|
||||
self.article_translations_map[at.language_code] = at
|
||||
elif c.is_dir():
|
||||
self.child_articles.append(ArticleOverview(
|
||||
self.child_articles.append(Article(
|
||||
directory=c,
|
||||
location_in_tree=self.location_in_tree.copy(),
|
||||
parent=self,
|
||||
))
|
||||
|
||||
# the tree is built
|
||||
self.article_translations.sort(key=lambda a: a.priority, reverse=True)
|
||||
self.overview_cards = "\n".join(a.get_overview_card() for a in self.article_translations)
|
||||
self.article_translations_list.sort(key=lambda a: a.priority, reverse=True)
|
||||
|
||||
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 build(self):
|
||||
# builds the tree structure to the dist directory
|
||||
self.dist_path.mkdir(parents=True, exist_ok=True)
|
||||
with Path(self.dist_path, "index.html").open("w") as f:
|
||||
f.write(self.get_overview())
|
||||
def __init_context__(self):
|
||||
self.context_shared["url"] = self.url
|
||||
self.context_shared["slug"] = self.slug
|
||||
|
||||
for at in self.article_translations:
|
||||
modified_at = datetime.fromisoformat(self.config["datetime"]) if "datetime" in self.config else datetime.fromtimestamp(self.directory.stat().st_mtime)
|
||||
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"] = []
|
||||
child_article_list = self.context["children"] = []
|
||||
|
||||
for article_translation in self.article_translations_list:
|
||||
self.context[article_translation.real_language_code] = article_translation.context
|
||||
translation_list.append(article_translation.context)
|
||||
|
||||
for child_article in self.child_articles:
|
||||
child_article_list.append(child_article.context)
|
||||
|
||||
# recursively build context
|
||||
for at in self.article_translations_list:
|
||||
at.__init_context__()
|
||||
for a in self.child_articles:
|
||||
a.__init_context__()
|
||||
|
||||
def build(self):
|
||||
self.dist_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with Path(self.dist_path, "index.html").open("w") as f:
|
||||
f.write(TEMPLATE["article"].render(self.context))
|
||||
|
||||
for at in self.article_translations_list:
|
||||
at.build()
|
||||
|
||||
for ca in self.child_articles:
|
||||
ca.build()
|
||||
for ac in self.child_articles:
|
||||
ac.build()
|
||||
|
||||
def _get_values(self, return_foreign_articles: bool = True) -> Dict[str, str]:
|
||||
r = {
|
||||
"article_url": self.url,
|
||||
"article_title": self.slug,
|
||||
"article_slug": self.slug,
|
||||
"article_overview_url": self.url,
|
||||
"article_overview_cards": self.overview_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())
|
||||
|
||||
|
||||
# GLOBALS
|
||||
logger = logging.getLogger("stsg.build")
|
||||
TEMPLATE = Template(Path(config.setup.source_directory, "templates"))
|
||||
ARTICLE_LAKE: Dict[str, ArticleOverview] = {}
|
||||
ARTICLE_LAKE: Dict[str, Article] = {}
|
||||
ARTICLE_REFERENCE_VALUES: DefaultDict[str, Dict[str, str]] = defaultdict(dict)
|
||||
|
||||
def build():
|
||||
@@ -196,14 +266,15 @@ def build():
|
||||
logger.info("copying static folder...")
|
||||
shutil.copytree(Path(config.setup.source_directory, "static"), Path(config.setup.dist_directory, "static"), dirs_exist_ok=True)
|
||||
|
||||
logger.info("reading page tree...")
|
||||
tree = ArticleOverview(directory=Path(config.setup.source_directory, "articles"))
|
||||
logger.info("building page tree...")
|
||||
tree = Article(directory=Path(config.setup.source_directory, "articles"), is_root=True)
|
||||
|
||||
logger.info("compiling tree context...")
|
||||
tree.__init_context__()
|
||||
|
||||
# build article reverence values
|
||||
for article_overview in ARTICLE_LAKE.values():
|
||||
ARTICLE_REFERENCE_VALUES[""].update(article_overview.get_article_values())
|
||||
for language_code, at in article_overview.article_translations_map.items():
|
||||
ARTICLE_REFERENCE_VALUES[language_code].update(at.get_article_values())
|
||||
import json
|
||||
with Path("context.json").open("w") as f:
|
||||
json.dump(tree.context, f, indent=4)
|
||||
|
||||
logger.info("writing page tree...")
|
||||
logger.info("dumping page tree...")
|
||||
tree.build()
|
||||
Reference in New Issue
Block a user