aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/blogcfile.5.ronn6
-rw-r--r--src/blogc-make/rules.c30
-rwxr-xr-xtests/blogc-make/check_blogc_make.sh.in48
3 files changed, 30 insertions, 54 deletions
diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn
index 2836bad..bb1592e 100644
--- a/man/blogcfile.5.ronn
+++ b/man/blogcfile.5.ronn
@@ -50,7 +50,7 @@ however these rules can be customized with the following settings, from the
* `atom_posts_per_page` (default: `10`):
Number of posts per page in the Atom feeds. If negative, all the posts are
- included. If `0`, no posts are include.
+ included. If negative or `0`, the `atom` and `atom_tags` build rules are disabled.
* `atom_prefix` (default: `atom`):
The prefix of the generated Atom feeds. It is relative to the output
@@ -100,8 +100,8 @@ however these rules can be customized with the following settings, from the
* `posts_per_page` (default: `10`):
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.
+ are included. If negative or `0`, the `index` and `pagination` build rules
+ are 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 aea9c0f..93f504c 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -36,6 +36,18 @@ posts_ordering(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable)
}
+static bool
+posts_pagination_enabled(bm_ctx_t *ctx, const char *variable)
+{
+ if (ctx == NULL || ctx->settings == NULL || ctx->settings->settings == NULL)
+ return false;
+
+ return 0 < strtol(
+ bc_trie_lookup(ctx->settings->settings, variable),
+ NULL, 10); // FIXME: improve
+}
+
+
static void
posts_pagination(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable)
{
@@ -61,6 +73,9 @@ index_outputlist(bm_ctx_t *ctx)
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
+ if (!posts_pagination_enabled(ctx, "posts_per_page"))
+ return NULL;
+
bc_slist_t *rv = NULL;
const char *html_ext = bc_trie_lookup(ctx->settings->settings,
"html_ext");
@@ -119,6 +134,9 @@ atom_outputlist(bm_ctx_t *ctx)
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
+ if (!posts_pagination_enabled(ctx, "atom_posts_per_page"))
+ return NULL;
+
bc_slist_t *rv = NULL;
const char *atom_prefix = bc_trie_lookup(ctx->settings->settings,
"atom_prefix");
@@ -173,6 +191,9 @@ atom_tags_outputlist(bm_ctx_t *ctx)
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return NULL;
+ if (!posts_pagination_enabled(ctx, "atom_posts_per_page"))
+ return NULL;
+
bc_slist_t *rv = NULL;
const char *atom_prefix = bc_trie_lookup(ctx->settings->settings,
"atom_prefix");
@@ -234,13 +255,13 @@ pagination_outputlist(bm_ctx_t *ctx)
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
+ if (!posts_pagination_enabled(ctx, "posts_per_page"))
+ return NULL;
+
long num_posts = bc_slist_length(ctx->posts_fctx);
long posts_per_page = strtol(
bc_trie_lookup(ctx->settings->settings, "posts_per_page"),
NULL, 10); // FIXME: improve
- if (posts_per_page <= 0)
- return NULL;
-
size_t pages = ceilf(((float) num_posts) / posts_per_page);
const char *pagination_prefix = bc_trie_lookup(ctx->settings->settings,
@@ -374,6 +395,9 @@ tags_outputlist(bm_ctx_t *ctx)
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return NULL;
+ if (!posts_pagination_enabled(ctx, "posts_per_page"))
+ return NULL;
+
bc_slist_t *rv = NULL;
const char *tag_prefix = bc_trie_lookup(ctx->settings->settings,
"tag_prefix");
diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in
index 001241a..20cf1f7 100755
--- a/tests/blogc-make/check_blogc_make.sh.in
+++ b/tests/blogc-make/check_blogc_make.sh.in
@@ -194,7 +194,6 @@ post11
EOF
${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
-grep "_build/index\\.html" "${TEMP}/output.txt"
grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/post/post01/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post02/index\\.html" "${TEMP}/output.txt"
@@ -210,34 +209,6 @@ grep "_build/post/post11/index\\.html" "${TEMP}/output.txt"
rm "${TEMP}/output.txt"
-cat > "${TEMP}/expected-index.html" <<EOF
-
-Listing: Post 11 - Sep 11, 2016, 12:00 AM GMT
-
-Listing: Post 10 - Sep 10, 2016, 12:00 AM GMT
-
-Listing: Post 09 - Sep 09, 2016, 12:00 AM GMT
-
-Listing: Post 08 - Sep 08, 2016, 12:00 AM GMT
-
-Listing: Post 07 - Sep 07, 2016, 12:00 AM GMT
-
-Listing: Post 06 - Sep 06, 2016, 12:00 AM GMT
-
-Listing: Post 05 - Sep 05, 2016, 12:00 AM GMT
-
-Listing: Post 04 - Sep 04, 2016, 12:00 AM GMT
-
-Listing: Post 03 - Sep 03, 2016, 12:00 AM GMT
-
-Listing: Post 02 - Sep 02, 2016, 12:00 AM GMT
-
-Listing: Post 01 - Sep 01, 2016, 12:00 AM GMT
-
-
-EOF
-diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"
-
cat > "${TEMP}/expected-atom.xml" <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
@@ -450,7 +421,6 @@ EOF
${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc-make -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
grep "_build/index\\.html" "${TEMP}/output.txt"
-grep "_build/atom\\.xml" "${TEMP}/output.txt"
grep "_build/post/post01/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post02/index\\.html" "${TEMP}/output.txt"
grep "_build/post/post03/index\\.html" "${TEMP}/output.txt"
@@ -491,24 +461,6 @@ Listing: Post 02 - Sep 02, 2016, 12:00 AM GMT
EOF
diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html"
-cat > "${TEMP}/expected-atom.xml" <<EOF
-<?xml version="1.0" encoding="utf-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
- <title type="text">Lol's Website</title>
- <id>/atom.xml</id>
- <updated></updated>
- <link href="http://example.org/" />
- <link href="http://example.org/atom.xml" rel="self" />
- <author>
- <name>Lol</name>
- <email>author@example.com</email>
- </author>
- <subtitle type="text">WAT?!</subtitle>
-
-</feed>
-EOF
-diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"
-
cat > "${TEMP}/expected-post-post01.html" <<EOF