diff options
-rw-r--r-- | man/blogcfile.5.ronn | 5 | ||||
-rw-r--r-- | src/blogc-make/rules.c | 12 | ||||
-rw-r--r-- | src/blogc-make/settings.c | 1 | ||||
-rwxr-xr-x | tests/blogc-make/check_blogc_make.sh.in | 220 |
4 files changed, 235 insertions, 3 deletions
diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn index 8f50e8c..fd77e1c 100644 --- a/man/blogcfile.5.ronn +++ b/man/blogcfile.5.ronn @@ -115,6 +115,11 @@ however these rules can be customized with the following settings, from the are included. If `0`, no post listing pages are generated. Also, if negative or `0`, the `pagination` build rule is disabled. + * `posts_sort` (default: `false`): + If true, blogc(1) will sort the posts by date, despite the order of the posts + in the `[posts]` section. It is compatible with `html_order` and `atom_order` + settings. + * `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 f1a0be9..96cf51d 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -31,10 +31,16 @@ posts_ordering(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable) return; // something is wrong, let's not add any variable const char *value = bm_ctx_settings_lookup_str(ctx, variable); - if (value != NULL && ((0 == strcmp(value, "ASC")) || (0 == strcmp(value, "asc")))) - return; // user explicitly asked for ASC + bool asc = 0 == strcasecmp(value, "asc"); + bool sort = bc_str_to_bool(bm_ctx_settings_lookup(ctx, "posts_sort")); - bc_trie_insert(variables, "FILTER_REVERSE", bc_strdup("1")); + if (sort) { + bc_trie_insert(variables, "FILTER_SORT", bc_strdup("1")); + } + + if ((sort && asc) || (!sort && !asc)) { + bc_trie_insert(variables, "FILTER_REVERSE", bc_strdup("1")); + } } diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c index 05e610a..be976e3 100644 --- a/src/blogc-make/settings.c +++ b/src/blogc-make/settings.c @@ -28,6 +28,7 @@ static const struct default_settings_map { {"main_template", "main.tmpl"}, {"source_ext", ".txt"}, {"listing_entry", NULL}, + {"posts_sort", NULL}, // pagination {"pagination_prefix", "page"}, diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in index 14223d0..36dfceb 100755 --- a/tests/blogc-make/check_blogc_make.sh.in +++ b/tests/blogc-make/check_blogc_make.sh.in @@ -755,6 +755,226 @@ diff -uN "${TEMP}/proj/_build/post/post11/index.html" "${TEMP}/expected-post-pos rm -rf "${TEMP}/proj/_build" +### default settings with some posts, order asc, posts_sort + +cat > "${TEMP}/proj/blogcfile" <<EOF +[global] +AUTHOR_NAME = Lol +AUTHOR_EMAIL = author@example.com +SITE_TITLE = Lol's Website +SITE_TAGLINE = WAT?! +BASE_DOMAIN = http://example.org + +[settings] +html_order = asc +atom_order = asc +posts_sort = yes + +[posts] +foo +bar +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/page/1/index\\.html" "${TEMP}/output.txt" +grep "_build/post/foo/index\\.html" "${TEMP}/output.txt" +grep "_build/post/bar/index\\.html" "${TEMP}/output.txt" + +rm "${TEMP}/output.txt" + +cat > "${TEMP}/expected-index.html" <<EOF + +Listing: Bar - Sep 01, 2016, 12:00 AM GMT + +Listing: Foo - Oct 01, 2016, 12:00 AM GMT + + +EOF +diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html" +diff -uN "${TEMP}/proj/_build/page/1/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>http://example.org/atom.xml</id> + <updated>2016-09-01T00:00:00Z</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> + + <entry> + <title type="text">Bar</title> + <id>http://example.org/post/bar/index.html</id> + <updated>2016-09-01T00:00:00Z</updated> + <published>2016-09-01T00:00:00Z</published> + <link href="http://example.org/post/bar/index.html" /> + <author> + <name>Lol</name> + <email>author@example.com</email> + </author> + <content type="html"><![CDATA[<p>This is bar.</p> +]]></content> + </entry> + + <entry> + <title type="text">Foo</title> + <id>http://example.org/post/foo/index.html</id> + <updated>2016-10-01T00:00:00Z</updated> + <published>2016-10-01T00:00:00Z</published> + <link href="http://example.org/post/foo/index.html" /> + <author> + <name>Lol</name> + <email>author@example.com</email> + </author> + <content type="html"><![CDATA[<p>This is foo.</p> +]]></content> + </entry> + +</feed> +EOF +diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml" + +cat > "${TEMP}/expected-post-foo.html" <<EOF + + +Foo - Oct 01, 2016, 12:00 AM GMT + +<p>This is foo.</p> + + +EOF +diff -uN "${TEMP}/proj/_build/post/foo/index.html" "${TEMP}/expected-post-foo.html" + +cat > "${TEMP}/expected-post-bar.html" <<EOF + + +Bar - Sep 01, 2016, 12:00 AM GMT + +<p>This is bar.</p> + + +EOF +diff -uN "${TEMP}/proj/_build/post/bar/index.html" "${TEMP}/expected-post-bar.html" + +rm -rf "${TEMP}/proj/_build" + + +### default settings with some posts, order desc, posts_sort + +cat > "${TEMP}/proj/blogcfile" <<EOF +[global] +AUTHOR_NAME = Lol +AUTHOR_EMAIL = author@example.com +SITE_TITLE = Lol's Website +SITE_TAGLINE = WAT?! +BASE_DOMAIN = http://example.org + +[settings] +posts_sort = yes + +[posts] +foo +bar +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/page/1/index\\.html" "${TEMP}/output.txt" +grep "_build/post/foo/index\\.html" "${TEMP}/output.txt" +grep "_build/post/bar/index\\.html" "${TEMP}/output.txt" + +rm "${TEMP}/output.txt" + +cat > "${TEMP}/expected-index.html" <<EOF + +Listing: Foo - Oct 01, 2016, 12:00 AM GMT + +Listing: Bar - Sep 01, 2016, 12:00 AM GMT + + +EOF +diff -uN "${TEMP}/proj/_build/index.html" "${TEMP}/expected-index.html" +diff -uN "${TEMP}/proj/_build/page/1/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>http://example.org/atom.xml</id> + <updated>2016-10-01T00:00:00Z</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> + + <entry> + <title type="text">Foo</title> + <id>http://example.org/post/foo/index.html</id> + <updated>2016-10-01T00:00:00Z</updated> + <published>2016-10-01T00:00:00Z</published> + <link href="http://example.org/post/foo/index.html" /> + <author> + <name>Lol</name> + <email>author@example.com</email> + </author> + <content type="html"><![CDATA[<p>This is foo.</p> +]]></content> + </entry> + + <entry> + <title type="text">Bar</title> + <id>http://example.org/post/bar/index.html</id> + <updated>2016-09-01T00:00:00Z</updated> + <published>2016-09-01T00:00:00Z</published> + <link href="http://example.org/post/bar/index.html" /> + <author> + <name>Lol</name> + <email>author@example.com</email> + </author> + <content type="html"><![CDATA[<p>This is bar.</p> +]]></content> + </entry> + +</feed> +EOF +diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml" + +cat > "${TEMP}/expected-post-foo.html" <<EOF + + +Foo - Oct 01, 2016, 12:00 AM GMT + +<p>This is foo.</p> + + +EOF +diff -uN "${TEMP}/proj/_build/post/foo/index.html" "${TEMP}/expected-post-foo.html" + +cat > "${TEMP}/expected-post-bar.html" <<EOF + + +Bar - Sep 01, 2016, 12:00 AM GMT + +<p>This is bar.</p> + + +EOF +diff -uN "${TEMP}/proj/_build/post/bar/index.html" "${TEMP}/expected-post-bar.html" + +rm -rf "${TEMP}/proj/_build" + + ### default settings with some posts, order asc, listing_entry cat > "${TEMP}/proj/content/hue.txt" <<EOF |