From 14b3aea798c0999f56a5555d90db3c332966d085 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 20 Mar 2018 23:00:17 +0100 Subject: make: allow to disable pagination by setting posts_per_page<0 --- man/blogc-make.1.ronn | 4 ++-- man/blogcfile.5.ronn | 7 +++++-- src/blogc-make/rules.c | 38 +++++++++++++++++++++++--------------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/man/blogc-make.1.ronn b/man/blogc-make.1.ronn index ca9c4da..2d51992 100644 --- a/man/blogc-make.1.ronn +++ b/man/blogc-make.1.ronn @@ -89,8 +89,8 @@ The rule passes the following helper variables to blogc(1): ### pagination -Build pagination pages from posts. This rule will be disabled if -`posts_per_page` is negative or `0` in blogcfile(5). +Build pagination pages from posts. This rule is disabled if `posts_per_page` +value in blogcfile(5) is negative or `0`. The rule passes the following helper variables to blogc(1): diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn index fb2d623..2836bad 100644 --- a/man/blogcfile.5.ronn +++ b/man/blogcfile.5.ronn @@ -49,7 +49,8 @@ however these rules can be customized with the following settings, from the section. * `atom_posts_per_page` (default: `10`): - Number of posts per page in the Atom feeds. + Number of posts per page in the Atom feeds. If negative, all the posts are + included. If `0`, no posts are include. * `atom_prefix` (default: `atom`): The prefix of the generated Atom feeds. It is relative to the output @@ -98,7 +99,9 @@ however these rules can be customized with the following settings, from the directories, and is relative to `content_dir` and the output directory. * `posts_per_page` (default: `10`): - Number of posts per page in the pagination pages. + Number of posts per page in the pagination pages. If negative, all the posts + are included. If `0`, no posts are included. Also, if negative or `0`, the + `pagination` build rule is disabled. * `source_ext` (default: `.txt`): The extension of the source files. diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c index 79d722a..e22fbea 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -35,6 +35,23 @@ posts_ordering(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable) } +static void +posts_pagination(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable) +{ + if (ctx == NULL || ctx->settings == NULL || ctx->settings->settings == NULL) + return; // something is wrong, let's not add any variable + + long posts_per_page = strtol( + bc_trie_lookup(ctx->settings->settings, "posts_per_page"), + NULL, 10); // FIXME: improve + if (posts_per_page >= 0) { + bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1")); + bc_trie_insert(variables, "FILTER_PER_PAGE", + bc_strdup(bc_trie_lookup(ctx->settings->settings, "posts_per_page"))); + } +} + + // INDEX RULE static bc_slist_t* @@ -66,9 +83,7 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args) int rv = 0; bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "FILTER_PER_PAGE", - bc_strdup(bc_trie_lookup(ctx->settings->settings, "posts_per_page"))); - bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1")); + posts_pagination(ctx, variables, "posts_per_page"); posts_ordering(ctx, variables, "html_order"); bc_trie_insert(variables, "DATE_FORMAT", bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format"))); @@ -123,10 +138,7 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args) int rv = 0; bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "FILTER_PER_PAGE", - bc_strdup(bc_trie_lookup(ctx->settings->settings, - "atom_posts_per_page"))); - bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1")); + posts_pagination(ctx, variables, "atom_posts_per_page"); posts_ordering(ctx, variables, "atom_order"); bc_trie_insert(variables, "DATE_FORMAT", bc_strdup("%Y-%m-%dT%H:%M:%SZ")); bc_trie_insert(variables, "MAKE_RULE", bc_strdup("atom")); @@ -183,10 +195,7 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args) size_t i = 0; bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "FILTER_PER_PAGE", - bc_strdup(bc_trie_lookup(ctx->settings->settings, - "atom_posts_per_page"))); - bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1")); + posts_pagination(ctx, variables, "atom_posts_per_page"); posts_ordering(ctx, variables, "atom_order"); bc_trie_insert(variables, "DATE_FORMAT", bc_strdup("%Y-%m-%dT%H:%M:%SZ")); bc_trie_insert(variables, "MAKE_RULE", bc_strdup("atom_tags")); @@ -258,6 +267,8 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args) size_t page = 1; bc_trie_t *variables = bc_trie_new(free); + // not using posts_pagination because we set FILTER_PAGE anyway, and the + // first value inserted in that function would be useless bc_trie_insert(variables, "FILTER_PER_PAGE", bc_strdup(bc_trie_lookup(ctx->settings->settings, "posts_per_page"))); posts_ordering(ctx, variables, "html_order"); @@ -385,10 +396,7 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args) size_t i = 0; bc_trie_t *variables = bc_trie_new(free); - bc_trie_insert(variables, "FILTER_PER_PAGE", - bc_strdup(bc_trie_lookup(ctx->settings->settings, - "atom_posts_per_page"))); - bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1")); + posts_pagination(ctx, variables, "atom_posts_per_page"); posts_ordering(ctx, variables, "html_order"); bc_trie_insert(variables, "DATE_FORMAT", bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format"))); -- cgit v1.2.3-18-g5258