feat: filling an article lake
This commit is contained in:
parent
63f8541a82
commit
603a7f5942
@ -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:
|
||||||
@ -96,9 +93,14 @@ class ArticleTranslation:
|
|||||||
class ArticleOverview:
|
class ArticleOverview:
|
||||||
def __init__(self, directory: Path, url: str = ""):
|
def __init__(self, directory: Path, url: str = ""):
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
self.name = self.directory.name
|
self.slug = self.directory.name
|
||||||
|
|
||||||
self.url = url + "/" + self.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.url = url + "/" + self.slug
|
||||||
self.dist_path = Path(DIST_DIRECTORY, self.url.strip("/"))
|
self.dist_path = Path(DIST_DIRECTORY, self.url.strip("/"))
|
||||||
|
|
||||||
self.child_articles: List[ArticleOverview] = []
|
self.child_articles: List[ArticleOverview] = []
|
||||||
@ -126,11 +128,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 +172,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()
|
Loading…
x
Reference in New Issue
Block a user