From 79c95a9ddbb2df134e79653578bace40fb83a4a5 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Tue, 15 Apr 2025 12:16:37 +0200 Subject: [PATCH] feat: small refactoring for building of urls --- stsg/build.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/stsg/build.py b/stsg/build.py index 332a01f..6fa8d8d 100644 --- a/stsg/build.py +++ b/stsg/build.py @@ -91,17 +91,21 @@ class ArticleTranslation: 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.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: str = url + "/" + self.slug - self.dist_path = Path(DIST_DIRECTORY, self.url.strip("/")) self.child_articles: List[ArticleOverview] = [] self.article_translations: List[ArticleTranslation] = [] @@ -110,7 +114,10 @@ class ArticleOverview: if c.is_file(): self.article_translations.append(ArticleTranslation(c, self)) elif c.is_dir(): - self.child_articles.append(ArticleOverview(c, self.url)) + self.child_articles.append(ArticleOverview( + directory=self.directory, + location_in_tree=self.location_in_tree, + )) # the tree is built self.article_translations.sort(key=lambda a: a.priority, reverse=True)