aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2017-08-03 02:44:36 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2017-08-03 02:44:36 +0200
commit59e1df233e351a91240c02ac55e8d97bda2f0e43 (patch)
tree846932a4e7761dd93188d1533095f252246c83f3 /src/blogc-make
parent803eb202e9d2d96fbb0de6f0514db2f0ab959d11 (diff)
downloadblogc-59e1df233e351a91240c02ac55e8d97bda2f0e43.tar.gz
blogc-59e1df233e351a91240c02ac55e8d97bda2f0e43.tar.bz2
blogc-59e1df233e351a91240c02ac55e8d97bda2f0e43.zip
make: added 'html_order' and 'atom_order' settings
these settings are used to change the order of the posts on the listings. by default, users are supposed to list their posts from older to newer in the blogcfile, and blogc-make will list them on descending order, both for html listings and atom listings.
Diffstat (limited to 'src/blogc-make')
-rw-r--r--src/blogc-make/rules.c20
-rw-r--r--src/blogc-make/settings.c2
2 files changed, 22 insertions, 0 deletions
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index dd59d51..f27ef91 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -21,6 +21,20 @@
#include "rules.h"
+static void
+posts_ordering(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
+
+ const char *value = bc_trie_lookup(ctx->settings->settings, variable);
+ if (value != NULL && ((0 == strcmp(value, "ASC")) || (0 == strcmp(value, "asc"))))
+ return; // user explicitly asked for ASC
+
+ bc_trie_insert(variables, "FILTER_REVERSE", bc_strdup("1"));
+}
+
+
// INDEX RULE
static bc_slist_t*
@@ -55,6 +69,7 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
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_ordering(ctx, variables, "html_order");
bc_trie_insert(variables, "DATE_FORMAT",
bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
bc_trie_insert(variables, "MAKE_RULE", bc_strdup("index"));
@@ -112,6 +127,7 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bc_strdup(bc_trie_lookup(ctx->settings->settings,
"atom_posts_per_page")));
bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1"));
+ 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"));
bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("atom"));
@@ -171,6 +187,7 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bc_strdup(bc_trie_lookup(ctx->settings->settings,
"atom_posts_per_page")));
bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1"));
+ 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"));
bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("atom"));
@@ -240,6 +257,7 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
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")));
+ posts_ordering(ctx, variables, "html_order");
bc_trie_insert(variables, "DATE_FORMAT",
bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
bc_trie_insert(variables, "MAKE_RULE", bc_strdup("pagination"));
@@ -301,6 +319,7 @@ posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bc_trie_insert(variables, "IS_POST", bc_strdup("1"));
bc_trie_insert(variables, "DATE_FORMAT",
bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
+ posts_ordering(ctx, variables, "html_order");
bc_trie_insert(variables, "MAKE_RULE", bc_strdup("posts"));
bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
@@ -363,6 +382,7 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bc_strdup(bc_trie_lookup(ctx->settings->settings,
"atom_posts_per_page")));
bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1"));
+ posts_ordering(ctx, variables, "html_order");
bc_trie_insert(variables, "DATE_FORMAT",
bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
bc_trie_insert(variables, "MAKE_RULE", bc_strdup("tags"));
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index c80feaa..9e24d41 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -37,10 +37,12 @@ static const struct default_settings_map {
{"index_prefix", NULL},
{"post_prefix", "post"},
{"tag_prefix", "tag"},
+ {"html_order", "DESC"},
// atom
{"atom_prefix", "atom"},
{"atom_ext", ".xml"},
+ {"atom_order", "DESC"},
// generic
{"date_format", "%b %d, %Y, %I:%M %p GMT"},