From 2bccd0a0297ff4fd1580e4e927a91ceb31c8cd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Tue, 16 Jul 2024 17:06:41 +0200 Subject: [PATCH] allow to not specify category metadata --- jssg/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jssg/models.py b/jssg/models.py index 6859e6b..1115a35 100644 --- a/jssg/models.py +++ b/jssg/models.py @@ -276,7 +276,10 @@ def __init__(self, content: str, **metadata) -> None: """ super().__init__(content, **metadata) self.timestamp = datetime.datetime.fromisoformat(metadata["date"]) - self.metadata["category"] = slugify(self.metadata["category"]) + if "category" in self.metadata : + self.metadata["category"] = slugify(self.metadata["category"]) + else : + self.metadata["category"] = "" @classmethod def load_glob( @@ -310,8 +313,9 @@ def load_post_list_with_category(cls, category) : def categories(self) : cat = set() for post in Post.load_glob(all = True) : - cat.add(post.metadata["category"]) - return list(cat) + if post.metadata["category"] != "" : + cat.add(post.metadata["category"]) + return cat @classmethod def get_categories(cls) :