feat: small refactoring for building of urls
This commit is contained in:
parent
0ca0fb90d6
commit
79c95a9ddb
@ -91,17 +91,21 @@ 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.slug = 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:
|
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)
|
logger.error("two articles have the same name at %s and %r", ARTICLE_LAKE[self.slug].directory, self.directory)
|
||||||
exit(1)
|
exit(1)
|
||||||
ARTICLE_LAKE[self.slug] = self
|
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.child_articles: List[ArticleOverview] = []
|
||||||
self.article_translations: List[ArticleTranslation] = []
|
self.article_translations: List[ArticleTranslation] = []
|
||||||
@ -110,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=self.directory,
|
||||||
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user