aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make/rules.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2018-03-20 23:00:17 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2018-03-20 23:00:17 +0100
commit14b3aea798c0999f56a5555d90db3c332966d085 (patch)
tree3e012ddd9083bb6b22b7d7132790584eed0454cd /src/blogc-make/rules.c
parent4c9ae70d3f7b99635f68796c8fca072a1baaf009 (diff)
downloadblogc-14b3aea798c0999f56a5555d90db3c332966d085.tar.gz
blogc-14b3aea798c0999f56a5555d90db3c332966d085.tar.bz2
blogc-14b3aea798c0999f56a5555d90db3c332966d085.zip
make: allow to disable pagination by setting posts_per_page<0
Diffstat (limited to 'src/blogc-make/rules.c')
-rw-r--r--src/blogc-make/rules.c38
1 files changed, 23 insertions, 15 deletions
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")));