Compare commits
No commits in common. "4f37283e685a51d8bed7ff93980dca580c592a2f" and "3fdbf13d95fce9535a123b00667b54faf9c988cd" have entirely different histories.
4f37283e68
...
3fdbf13d95
@ -10,6 +10,8 @@ from bs4 import BeautifulSoup
|
||||
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:
|
||||
for key, value in values.items():
|
||||
@ -36,6 +38,7 @@ class Template:
|
||||
self.overview: str = (self.folder / "overview.html").read_text()
|
||||
self.overview_card: str = (self.folder / "overview_card.html").read_text()
|
||||
|
||||
TEMPLATE = Template(Path(SOURCE_DIRECTORY, "templates"))
|
||||
|
||||
|
||||
class ArticleTranslation:
|
||||
@ -48,9 +51,8 @@ class ArticleTranslation:
|
||||
if self.file.suffix == ".md":
|
||||
self.article_content = markdown.markdown(self.article_content)
|
||||
|
||||
self.location_in_tree = [self.language_code, *self.article_overview.location_in_tree]
|
||||
self.url = "/" + "/".join(self.location_in_tree)
|
||||
self.dist_path = Path(DIST_DIRECTORY, *self.location_in_tree)
|
||||
self.url = "/" + self.language_code + self.article_overview.url
|
||||
self.dist_path = Path(DIST_DIRECTORY, self.url.strip("/"))
|
||||
|
||||
_language_info = DEFAULT_LANGUAGE
|
||||
parsed_language_code = self.language_code.lower().replace("-", "_")
|
||||
@ -92,20 +94,12 @@ class ArticleTranslation:
|
||||
|
||||
|
||||
class ArticleOverview:
|
||||
def __init__(self, directory: Path, location_in_tree: Optional[List[str]] = None):
|
||||
def __init__(self, directory: Path, url: str = ""):
|
||||
self.directory = directory
|
||||
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.name = self.directory.name
|
||||
|
||||
self.url = url + "/" + self.name
|
||||
self.dist_path = Path(DIST_DIRECTORY, self.url.strip("/"))
|
||||
|
||||
self.child_articles: List[ArticleOverview] = []
|
||||
self.article_translations: List[ArticleTranslation] = []
|
||||
@ -114,10 +108,7 @@ class ArticleOverview:
|
||||
if c.is_file():
|
||||
self.article_translations.append(ArticleTranslation(c, self))
|
||||
elif c.is_dir():
|
||||
self.child_articles.append(ArticleOverview(
|
||||
directory=c,
|
||||
location_in_tree=self.location_in_tree,
|
||||
))
|
||||
self.child_articles.append(ArticleOverview(c, self.url))
|
||||
|
||||
# the tree is built
|
||||
self.article_translations.sort(key=lambda a: a.priority, reverse=True)
|
||||
@ -135,10 +126,11 @@ class ArticleOverview:
|
||||
for ca in self.child_articles:
|
||||
ca.build()
|
||||
|
||||
|
||||
def _get_values(self) -> Dict[str, str]:
|
||||
return {
|
||||
"overview_cards": self.overview_cards,
|
||||
"overview_slug": self.slug,
|
||||
"overview_slug": self.name,
|
||||
}
|
||||
|
||||
def get_overview(self) -> str:
|
||||
@ -179,17 +171,9 @@ def copy_static():
|
||||
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():
|
||||
logger.info("building static page")
|
||||
|
||||
copy_static()
|
||||
tree = ArticleOverview(directory=Path(SOURCE_DIRECTORY, "pages"))
|
||||
|
||||
print(ARTICLE_LAKE)
|
||||
|
||||
tree.build()
|
@ -10,16 +10,13 @@ ARTICLE_PREVIEW_LENGTH = 200
|
||||
# FOR DEVELOPMENT
|
||||
CODE_DIRECTORY = "stsg"
|
||||
|
||||
|
||||
class TypedLanguageInformation(typing_extensions.TypedDict):
|
||||
flag: str
|
||||
name: str
|
||||
native_name: str
|
||||
priority: typing_extensions.NotRequired[int]
|
||||
|
||||
|
||||
# LANGUAGE INFORMATION
|
||||
LANGUAGE_INFORMATION: typing.Dict[str, TypedLanguageInformation] = {
|
||||
LANGUAGE_INFORMATION: typing.Dict[str, {
|
||||
"flag": str,
|
||||
"name": str,
|
||||
"native_name": str,
|
||||
"priority": typing_extensions.NotRequired[int],
|
||||
}] = {
|
||||
"af": {
|
||||
"flag": "🇿🇦",
|
||||
"name": "Afrikaans",
|
||||
@ -769,4 +766,4 @@ LANGUAGE_INFORMATION: typing.Dict[str, TypedLanguageInformation] = {
|
||||
}
|
||||
|
||||
|
||||
DEFAULT_LANGUAGE: TypedLanguageInformation = LANGUAGE_INFORMATION["de"]
|
||||
DEFAULT_LANGUAGE = LANGUAGE_INFORMATION["de"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user