From 2b617e5a735722754106f875631262b5790f17c0 Mon Sep 17 00:00:00 2001 From: ClmntBcqt <129279765+ClmntBcqt@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:41:08 +0200 Subject: [PATCH] Allow no posts (#55) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix : Allow no post for sitemap --------- Co-authored-by: Clément --- jssg/models.py | 7 +++++-- jssg/sitemaps.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/jssg/models.py b/jssg/models.py index 586e6c4..2fe98c3 100644 --- a/jssg/models.py +++ b/jssg/models.py @@ -373,8 +373,11 @@ def get_postlists(cls) : @classmethod def get_pages(cls) : - return [{"page": page} for page in range(1, cls().nb_pages+1)] - + if len(list(Post.load_glob(all = True))) > 0 : + return [{"page": page} for page in range(1, cls().nb_pages+1)] + else : + return [] + @property def posts(self) : posts = sorted(Post.load_glob(all=True), key=lambda p: p.timestamp, reverse=True) diff --git a/jssg/sitemaps.py b/jssg/sitemaps.py index ab625a6..b8da749 100644 --- a/jssg/sitemaps.py +++ b/jssg/sitemaps.py @@ -13,7 +13,10 @@ def get_urls(self, site=None, **kwargs): class ConstantUrlSitemap(MySitemap) : def items(self) : - return ["/", "/atom.xml", "/sitemap.xml"] + if len(list(Post.load_glob(all = True))) > 0 : + return ["/", "/atom.xml", "/sitemap.xml"] + else : + return ["/", "/sitemap.xml"] def location(self, url) -> str: return url