|
|
|
@@ -10,8 +10,6 @@ from bs4 import BeautifulSoup
|
|
|
|
from .config import SOURCE_DIRECTORY, DIST_DIRECTORY, LANGUAGE_INFORMATION, ARTICLE_PREVIEW_LENGTH, DEFAULT_LANGUAGE
|
|
|
|
from .config import SOURCE_DIRECTORY, DIST_DIRECTORY, LANGUAGE_INFORMATION, ARTICLE_PREVIEW_LENGTH, DEFAULT_LANGUAGE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("stsg.build")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def replace_values(template: str, values: Dict[str, str]) -> str:
|
|
|
|
def replace_values(template: str, values: Dict[str, str]) -> str:
|
|
|
|
for key, value in values.items():
|
|
|
|
for key, value in values.items():
|
|
|
|
@@ -38,7 +36,6 @@ class Template:
|
|
|
|
self.overview: str = (self.folder / "overview.html").read_text()
|
|
|
|
self.overview: str = (self.folder / "overview.html").read_text()
|
|
|
|
self.overview_card: str = (self.folder / "overview_card.html").read_text()
|
|
|
|
self.overview_card: str = (self.folder / "overview_card.html").read_text()
|
|
|
|
|
|
|
|
|
|
|
|
TEMPLATE = Template(Path(SOURCE_DIRECTORY, "templates"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleTranslation:
|
|
|
|
class ArticleTranslation:
|
|
|
|
@@ -51,8 +48,9 @@ class ArticleTranslation:
|
|
|
|
if self.file.suffix == ".md":
|
|
|
|
if self.file.suffix == ".md":
|
|
|
|
self.article_content = markdown.markdown(self.article_content)
|
|
|
|
self.article_content = markdown.markdown(self.article_content)
|
|
|
|
|
|
|
|
|
|
|
|
self.url = "/" + self.language_code + self.article_overview.url
|
|
|
|
self.location_in_tree = [self.language_code, *self.article_overview.location_in_tree]
|
|
|
|
self.dist_path = Path(DIST_DIRECTORY, self.url.strip("/"))
|
|
|
|
self.url = "/" + "/".join(self.location_in_tree)
|
|
|
|
|
|
|
|
self.dist_path = Path(DIST_DIRECTORY, *self.location_in_tree)
|
|
|
|
|
|
|
|
|
|
|
|
_language_info = DEFAULT_LANGUAGE
|
|
|
|
_language_info = DEFAULT_LANGUAGE
|
|
|
|
parsed_language_code = self.language_code.lower().replace("-", "_")
|
|
|
|
parsed_language_code = self.language_code.lower().replace("-", "_")
|
|
|
|
@@ -94,12 +92,20 @@ class ArticleTranslation:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleOverview:
|
|
|
|
class ArticleOverview:
|
|
|
|
def __init__(self, directory: Path, url: str = ""):
|
|
|
|
def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None):
|
|
|
|
self.directory = directory
|
|
|
|
self.directory = directory
|
|
|
|
self.name = self.directory.name
|
|
|
|
self.slug = self.directory.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(DIST_DIRECTORY, *self.location_in_tree)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.url = url + "/" + self.name
|
|
|
|
|
|
|
|
self.dist_path = Path(DIST_DIRECTORY, self.url.strip("/"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.child_articles: List[ArticleOverview] = []
|
|
|
|
self.child_articles: List[ArticleOverview] = []
|
|
|
|
self.article_translations: List[ArticleTranslation] = []
|
|
|
|
self.article_translations: List[ArticleTranslation] = []
|
|
|
|
@@ -108,7 +114,10 @@ class ArticleOverview:
|
|
|
|
if c.is_file():
|
|
|
|
if c.is_file():
|
|
|
|
self.article_translations.append(ArticleTranslation(c, self))
|
|
|
|
self.article_translations.append(ArticleTranslation(c, self))
|
|
|
|
elif c.is_dir():
|
|
|
|
elif c.is_dir():
|
|
|
|
self.child_articles.append(ArticleOverview(c, self.url))
|
|
|
|
self.child_articles.append(ArticleOverview(
|
|
|
|
|
|
|
|
directory=c,
|
|
|
|
|
|
|
|
location_in_tree=self.location_in_tree,
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
# the tree is built
|
|
|
|
# the tree is built
|
|
|
|
self.article_translations.sort(key=lambda a: a.priority, reverse=True)
|
|
|
|
self.article_translations.sort(key=lambda a: a.priority, reverse=True)
|
|
|
|
@@ -126,11 +135,10 @@ class ArticleOverview:
|
|
|
|
for ca in self.child_articles:
|
|
|
|
for ca in self.child_articles:
|
|
|
|
ca.build()
|
|
|
|
ca.build()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_values(self) -> Dict[str, str]:
|
|
|
|
def _get_values(self) -> Dict[str, str]:
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
"overview_cards": self.overview_cards,
|
|
|
|
"overview_cards": self.overview_cards,
|
|
|
|
"overview_slug": self.name,
|
|
|
|
"overview_slug": self.slug,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def get_overview(self) -> str:
|
|
|
|
def get_overview(self) -> str:
|
|
|
|
@@ -171,9 +179,17 @@ def copy_static():
|
|
|
|
shutil.copy2(src_file, dest_file)
|
|
|
|
shutil.copy2(src_file, dest_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GLOBALS
|
|
|
|
|
|
|
|
logger = logging.getLogger("stsg.build")
|
|
|
|
|
|
|
|
TEMPLATE = Template(Path(SOURCE_DIRECTORY, "templates"))
|
|
|
|
|
|
|
|
ARTICLE_LAKE: Dict[str, ArticleOverview] = {}
|
|
|
|
|
|
|
|
|
|
|
|
def build():
|
|
|
|
def build():
|
|
|
|
logger.info("building static page")
|
|
|
|
logger.info("building static page")
|
|
|
|
|
|
|
|
|
|
|
|
copy_static()
|
|
|
|
copy_static()
|
|
|
|
tree = ArticleOverview(directory=Path(SOURCE_DIRECTORY, "pages"))
|
|
|
|
tree = ArticleOverview(directory=Path(SOURCE_DIRECTORY, "pages"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(ARTICLE_LAKE)
|
|
|
|
|
|
|
|
|
|
|
|
tree.build()
|
|
|
|
tree.build()
|