|
|
|
@@ -7,6 +7,8 @@ import markdown
|
|
|
|
from typing import Optional, Union, Dict, Generator, List, DefaultDict
|
|
|
|
from typing import Optional, Union, Dict, Generator, List, DefaultDict
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from collections import defaultdict
|
|
|
|
from collections import defaultdict
|
|
|
|
|
|
|
|
import toml
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
|
|
from . import config
|
|
|
|
from . import config
|
|
|
|
|
|
|
|
|
|
|
|
@@ -82,6 +84,7 @@ class ArticleTranslation:
|
|
|
|
"article_overview_url": self.article_overview.url,
|
|
|
|
"article_overview_url": self.article_overview.url,
|
|
|
|
"article_slug": self.article_overview.slug,
|
|
|
|
"article_slug": self.article_overview.slug,
|
|
|
|
"article_title": self.title,
|
|
|
|
"article_title": self.title,
|
|
|
|
|
|
|
|
"article_datetime": self.article_overview.article_written.strftime(config.formatting.datetime_format),
|
|
|
|
"article_language_name": self.language_name,
|
|
|
|
"article_language_name": self.language_name,
|
|
|
|
"article_language_code": self.language_code,
|
|
|
|
"article_language_code": self.language_code,
|
|
|
|
"article_language_flag": self.language_flag,
|
|
|
|
"article_language_flag": self.language_flag,
|
|
|
|
@@ -109,13 +112,19 @@ class ArticleTranslation:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleOverview:
|
|
|
|
class ArticleOverview:
|
|
|
|
def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None):
|
|
|
|
def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None, is_root: bool = False):
|
|
|
|
self.directory = directory
|
|
|
|
self.directory = directory
|
|
|
|
self.slug = self.directory.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.article_written = self.directory.stat().st_mtime
|
|
|
|
article_config = {}
|
|
|
|
|
|
|
|
if (self.directory / "index.toml").exists():
|
|
|
|
|
|
|
|
article_config = toml.load(self.directory / "index.toml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.slug = article_config.get("name", self.directory.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.article_written = datetime.datetime.fromisoformat(article_config["datetime"]) if "datetime" in article_config else datetime.datetime.fromtimestamp(self.directory.stat().st_mtime)
|
|
|
|
|
|
|
|
|
|
|
|
self.location_in_tree: List[str] = location_in_tree or []
|
|
|
|
self.location_in_tree: List[str] = location_in_tree or []
|
|
|
|
|
|
|
|
if not is_root:
|
|
|
|
self.location_in_tree.append(self.slug)
|
|
|
|
self.location_in_tree.append(self.slug)
|
|
|
|
self.url = "/" + "/".join(self.location_in_tree)
|
|
|
|
self.url = "/" + "/".join(self.location_in_tree)
|
|
|
|
self.dist_path = Path(config.setup.dist_directory, *self.location_in_tree)
|
|
|
|
self.dist_path = Path(config.setup.dist_directory, *self.location_in_tree)
|
|
|
|
@@ -130,6 +139,9 @@ class ArticleOverview:
|
|
|
|
self.article_translations_map: Dict[str, ArticleTranslation] = {}
|
|
|
|
self.article_translations_map: Dict[str, ArticleTranslation] = {}
|
|
|
|
|
|
|
|
|
|
|
|
for c in self.directory.iterdir():
|
|
|
|
for c in self.directory.iterdir():
|
|
|
|
|
|
|
|
if c.name == "index.toml":
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
if c.is_file():
|
|
|
|
if c.is_file():
|
|
|
|
at = ArticleTranslation(c, self)
|
|
|
|
at = ArticleTranslation(c, self)
|
|
|
|
self.article_translations.append(at)
|
|
|
|
self.article_translations.append(at)
|
|
|
|
@@ -163,6 +175,7 @@ class ArticleOverview:
|
|
|
|
"article_url": self.url,
|
|
|
|
"article_url": self.url,
|
|
|
|
"article_title": self.slug,
|
|
|
|
"article_title": self.slug,
|
|
|
|
"article_slug": self.slug,
|
|
|
|
"article_slug": self.slug,
|
|
|
|
|
|
|
|
"article_datetime": self.article_written.strftime(config.formatting.datetime_format),
|
|
|
|
"article_overview_url": self.url,
|
|
|
|
"article_overview_url": self.url,
|
|
|
|
"article_overview_cards": self.overview_cards,
|
|
|
|
"article_overview_cards": self.overview_cards,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -197,7 +210,7 @@ def build():
|
|
|
|
shutil.copytree(Path(config.setup.source_directory, "static"), Path(config.setup.dist_directory, "static"), dirs_exist_ok=True)
|
|
|
|
shutil.copytree(Path(config.setup.source_directory, "static"), Path(config.setup.dist_directory, "static"), dirs_exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("reading page tree...")
|
|
|
|
logger.info("reading page tree...")
|
|
|
|
tree = ArticleOverview(directory=Path(config.setup.source_directory, "articles"))
|
|
|
|
tree = ArticleOverview(directory=Path(config.setup.source_directory, "articles"), is_root=True)
|
|
|
|
|
|
|
|
|
|
|
|
# build article reverence values
|
|
|
|
# build article reverence values
|
|
|
|
for article_overview in ARTICLE_LAKE.values():
|
|
|
|
for article_overview in ARTICLE_LAKE.values():
|
|
|
|
|