Skip to content

Commit

Permalink
Fix : allow to have no posts (#53)
Browse files Browse the repository at this point in the history
urls for blog are not generated anymore if there is no blog posts

Co-authored-by: Clément <[email protected]>
  • Loading branch information
ClmntBcqt and Clément authored Aug 6, 2024
1 parent ff758f2 commit e8e1ad6
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 327 deletions.
22 changes: 0 additions & 22 deletions content/posts/ia.md

This file was deleted.

69 changes: 0 additions & 69 deletions content/posts/manipuler-pdf.md

This file was deleted.

71 changes: 0 additions & 71 deletions content/posts/post1.md

This file was deleted.

42 changes: 0 additions & 42 deletions content/posts/post2.md

This file was deleted.

58 changes: 0 additions & 58 deletions content/posts/post3.md

This file was deleted.

12 changes: 0 additions & 12 deletions content/posts/test/19700101_hello.md

This file was deleted.

25 changes: 0 additions & 25 deletions content/posts/xs-compromise.md

This file was deleted.

3 changes: 2 additions & 1 deletion jssg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ def __init__(self, category = "", page = 1) -> None:
else :
self.posts_by_page = nb_posts

self.nb_pages = ceil(nb_posts / self.posts_by_page) # number of posts / number of posts by page
if self.posts_by_page > 0:
self.nb_pages = ceil(nb_posts / self.posts_by_page) # number of posts / number of posts by page

@classmethod
def load_post_list_with_category(cls, category, page) :
Expand Down
61 changes: 34 additions & 27 deletions jssg/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,6 @@
name="page",
distill_func=Page.get_pages,
),

distill_path("atom.xml", views.PostFeedsView(), name="atom_feed"),
distill_path(
"posts/page<int:page>.html",
views.PostListView.as_view(),
name = "post-index",
distill_func = PostList.get_pages
),
distill_path(
"posts/category/<slug:category>/page<int:page>.html",
views.PostListView.as_view(),
name = "post-category",
distill_func = PostList.get_categories_and_pages
),
distill_path(
"posts/articles/<slug:slug>.html",
views.PostView.as_view(),
name="post",
distill_func=Post.get_posts,
),
distill_path(
"posts/articles/<path:dir>/<slug:slug>.html",
views.PostView.as_view(),
name="post",
distill_func=Post.get_posts,
),

distill_path(
"sitemap.xml",
sitemap,
Expand All @@ -77,3 +50,37 @@
name="django.contrib.sitemaps.views.sitemap",
)
]

if len(list(Post.get_posts())) > 0 :
urlpatterns += [
distill_path("atom.xml", views.PostFeedsView(), name="atom_feed"),
distill_path(
"posts/page<int:page>.html",
views.PostListView.as_view(),
name = "post-index",
distill_func = PostList.get_pages
),
distill_path(
"posts/articles/<slug:slug>.html",
views.PostView.as_view(),
name="post",
distill_func=Post.get_posts,
),
distill_path(
"posts/articles/<path:dir>/<slug:slug>.html",
views.PostView.as_view(),
name="post",
distill_func=Post.get_posts,
),
]

if len(PostList().categories) > 0 :
urlpatterns += [
distill_path(
"posts/category/<slug:category>/page<int:page>.html",
views.PostListView.as_view(),
name = "post-category",
distill_func = PostList.get_categories_and_pages
),

]

0 comments on commit e8e1ad6

Please sign in to comment.