Skip to content

Commit

Permalink
Allow no posts (#55)
Browse files Browse the repository at this point in the history
* Fix : Allow no post for sitemap

---------

Co-authored-by: Clément <[email protected]>
  • Loading branch information
ClmntBcqt and Clément authored Aug 6, 2024
1 parent e8e1ad6 commit 2b617e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions jssg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion jssg/sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2b617e5

Please sign in to comment.