diff --git a/README.md b/README.md index 50b98ce..8795e95 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Otherwise, you have to configure the following settings : Other useful settings : - Default metadata : `JFME_DEFAULT_METADATA_DICT` and `JFME_DEFAULT_METADATA_FILEPATH` allow to set default metadata for pages and posts. The first one is a python dictionary and the second one is a Path to a file having the same format as metadata section in pages. The order, from less to most priority is : `JFME_DEFAULT_METADATA_DICT` then `JFME_DEFAULT_METADATA_FILEPATH` then page matadata. +- Posts pagination : `JFME_NUMBER_OF_POSTS_BY_PAGE` give the maximum number of posts in a posts list page. If not set, all posts will be in the first page. ### `Dockerfile` : - In the `# Copy source dir` section, add `COPY / /` for each content directory in `JFME_CONTENT_DIRS` diff --git a/content/templates/jinja2/post-list.html b/content/templates/jinja2/post-list.html index f7256f1..256af72 100644 --- a/content/templates/jinja2/post-list.html +++ b/content/templates/jinja2/post-list.html @@ -56,31 +56,36 @@

{{ post.title }}

{% endfor %} -
-{% if object.page > 1 %} - {% if object.category != "" %} - Page précédente - {% else %} - Page précédente - {% endif %} -{% endif %} -{% if object.page < object.nb_pages %} - {% if object.category != "" %} - Page suivante - {% else %} - Page suivante - {% endif %} +{% if object.nb_pages > 1 %} +
+ {% if object.page > 1 %} + {% if object.category != "" %} + Page précédente + {% else %} + Page précédente + {% endif %} + {% endif %} + + {% if object.page < object.nb_pages %} + {% if object.category != "" %} + Page suivante + {% else %} + Page suivante + {% endif %} + {% endif %} +
+ +
+ Pages : + {% for page in range(1, object.nb_pages+1) %} + {% if object.category != "" %} + {{page}} + {% else %} + {{page}} + {% endif %} + {% endfor %} +
{% endif %} -
-
-Pages : -{% for page in range(1, object.nb_pages+1) %} - {% if object.category != "" %} - {{page}} - {% else %} - {{page}} - {% endif %} -{% endfor %} -
+ {% endblock %} \ No newline at end of file diff --git a/jssg/models.py b/jssg/models.py index 513a0de..db7b0a7 100644 --- a/jssg/models.py +++ b/jssg/models.py @@ -335,11 +335,18 @@ class PostList : def __init__(self, category = "", page = 1) -> None: self.category = category self.page = page - self.posts_by_page = settings.JFME_NUMBER_OF_POSTS_BY_PAGE - if self.category == "" : - self.nb_pages = ceil(len(list(Post.load_glob(all=True))) / self.posts_by_page) # number of posts / number of posts by page + + if category == "" : + nb_posts = len(list(Post.load_glob(all = True))) else : - self.nb_pages = ceil(len(list(filter(lambda p: p.metadata["category"] == self.category, Post.load_glob(all=True)))) / self.posts_by_page) # number of posts of the category / number of posts by page + nb_posts = len(list(filter(lambda p: p.metadata["category"] == self.category, Post.load_glob(all=True)))) + + if hasattr(settings, "JFME_NUMBER_OF_POSTS_BY_PAGE") : + self.posts_by_page = settings.JFME_NUMBER_OF_POSTS_BY_PAGE + 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 @classmethod def load_post_list_with_category(cls, category, page) : diff --git a/jssg/settings.py b/jssg/settings.py index 189205f..8baf717 100644 --- a/jssg/settings.py +++ b/jssg/settings.py @@ -54,7 +54,7 @@ JFME_STATIC_DIRS = [path / "static" for path in JFME_CONTENT_DIRS] JFME_DEFAULT_METADATA_DICT = {"slug": "index", } # The order of include is : JFME_DEFAULT_METADATA_DICT then JFME_DEFAULT_METADATA_FILEPATH then page metadata JFME_DEFAULT_METADATA_FILEPATH = BASE_DIR / "jssg" / "default_metadata.txt" # If a metadata is specified more than once, the last included is retained -JFME_NUMBER_OF_POSTS_BY_PAGE = 3 +JFME_NUMBER_OF_POSTS_BY_PAGE = 3 # no pagination of posts if not set JFME_CONTENT_REQUIRED_METADATA = ["title", "slug", "lang", "description"] JFME_SITEMAP_LASTMOD_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" # strftime format, see https://docs.python.org/fr/3.6/library/datetime.html#strftime-and-strptime-behavior, see https://www.sitemaps.org/protocol.html#lastmoddef for allowed datetime formats