aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/blogcfile.5.ronn15
-rw-r--r--src/blogc-make/ctx.c29
-rw-r--r--src/blogc-make/ctx.h1
-rw-r--r--src/blogc-make/settings.c1
-rwxr-xr-xtests/blogc-make/check_blogc_make.sh.in251
5 files changed, 285 insertions, 12 deletions
diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn
index cbda4c4..edca45c 100644
--- a/man/blogcfile.5.ronn
+++ b/man/blogcfile.5.ronn
@@ -43,6 +43,12 @@ however these rules can be customized with the following settings, from the
* `atom_ext` (default: `.xml`):
The extension of the generated Atom feeds.
+ * `atom_legacy_entry_id` (default: `false`):
+ Before `0.14.0` blogc-make was generating "broken" entry IDs in the atom feeds.
+ This behavior was fixed in version `0.14.0` and current users that don't want
+ to have their old posts re-shared due to the change of IDs should set this to
+ `true`, to keep using the old format.
+
* `atom_order` (default: `DESC`):
The ordering (`ASC` or `DESC`) of the Atom feeds. Please note that the files
are not sorted by date, they are sorted by their order in the `[posts]`
@@ -58,11 +64,10 @@ however these rules can be customized with the following settings, from the
be `atom.xml`, the Atom feed for the `foo` tag will be `atom/foo.xml` and so
on.
- * `atom_legacy_entry_id` (default: `false`):
- Before `0.14.0` blogc-make was generating "broken" entry IDs in the atom feeds.
- This behavior was fixed in version `0.14.0` and current users that don't want
- to have their old posts re-shared due to the change of IDs should set this to
- `true`, to keep using the old format.
+ * `atom_template` (default: internal template)
+ The template file that should be used when building Atom feeds. This file
+ is relative to `template_dir`. If not provided, an internal default template
+ will be used instead.
* `content_dir` (default: `content`):
The directory that stores the source files. This directory is relative
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index 909a526..8f47e37 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -177,15 +177,29 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
return NULL;
bm_settings_t *settings = bm_settings_parse(content, content_len, err);
- if (*err != NULL) {
+ if (settings == NULL || *err != NULL) {
free(content);
return NULL;
}
free(content);
- char *atom_template = bm_atom_deploy(settings, err);
- if (*err != NULL) {
- return NULL;
+ const char *template_dir = bc_trie_lookup(settings->settings, "template_dir");
+ if (template_dir == NULL)
+ template_dir = "";
+
+ char *atom_template = NULL;
+ bool atom_template_tmp = false;
+ const char *atom_template_conf = bc_trie_lookup(settings->settings,
+ "atom_template");
+ if (atom_template_conf != NULL) {
+ atom_template = bc_strdup_printf("%s/%s", template_dir, atom_template_conf);
+ }
+ else {
+ atom_template = bm_atom_deploy(settings, err);
+ atom_template_tmp = true;
+ if (*err != NULL) {
+ return NULL;
+ }
}
bm_ctx_t *rv = NULL;
@@ -221,13 +235,12 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
// can't return null and set error after this!
- const char *template_dir = bm_ctx_settings_lookup(rv, "template_dir");
-
char *main_template = bc_strdup_printf("%s/%s", template_dir,
bm_ctx_settings_lookup(rv, "main_template"));
rv->main_template_fctx = bm_filectx_new(rv, main_template, NULL, NULL);
free(main_template);
+ rv->atom_template_tmp = atom_template_tmp;
rv->atom_template_fctx = bm_filectx_new(rv, atom_template, NULL, NULL);
free(atom_template);
@@ -325,7 +338,9 @@ bm_ctx_free_internal(bm_ctx_t *ctx)
free(ctx->output_dir);
ctx->output_dir = NULL;
- bm_atom_destroy(ctx->atom_template_fctx->path);
+ if (ctx->atom_template_tmp)
+ bm_atom_destroy(ctx->atom_template_fctx->path);
+ ctx->atom_template_tmp = false;
bm_filectx_free(ctx->main_template_fctx);
ctx->main_template_fctx = NULL;
diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h
index df512e1..8d82816 100644
--- a/src/blogc-make/ctx.h
+++ b/src/blogc-make/ctx.h
@@ -49,6 +49,7 @@ typedef struct {
bool dev;
bool verbose;
+ bool atom_template_tmp;
bm_settings_t *settings;
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index 719afe1..e103e42 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -24,6 +24,7 @@ static const struct default_settings_map {
// source
{"content_dir", "content"},
{"template_dir", "templates"},
+ {"atom_template", NULL}, // default: atom.c
{"main_template", "main.tmpl"},
{"source_ext", ".txt"},
diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in
index 2a82b2d..35a7c41 100755
--- a/tests/blogc-make/check_blogc_make.sh.in
+++ b/tests/blogc-make/check_blogc_make.sh.in
@@ -436,6 +436,257 @@ diff -uN "${TEMP}/proj/_build/post/post11/index.html" "${TEMP}/expected-post-pos
rm -rf "${TEMP}/proj/_build"
+### default settings with some posts, custom atom template
+
+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_per_page = -1
+atom_posts_per_page = -1
+atom_template = atom.tmpl
+
+[posts]
+post01
+post02
+post03
+post04
+post05
+post06
+post07
+post08
+post09
+post10
+post11
+EOF
+
+cat > "${TEMP}/proj/templates/atom.tmpl" <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title type="text">{{ SITE_TITLE }}{% ifdef FILTER_TAG %} - {{ FILTER_TAG }}{% endif %}</title>
+ <id>{{ BASE_URL }}/atom/{% ifdef FILTER_TAG %}{{ FILTER_TAG }}/{% endif %}</id>
+ <updated>{{ DATE_FIRST_FORMATTED }}</updated>
+ <link href="{{ BASE_DOMAIN }}{{ BASE_URL }}/" />
+ <link href="{{ BASE_DOMAIN }}{{ BASE_URL }}/atom/{% ifdef FILTER_TAG %}{{ FILTER_TAG }}/{% endif %}" rel="self" />
+ <author>
+ <name>{{ AUTHOR_NAME }}</name>
+ <email>{{ AUTHOR_EMAIL }}</email>
+ </author>
+ <subtitle type="text">{{ SITE_TAGLINE }}</subtitle>
+ {% block listing %}
+ <entry>
+ <title type="text">{{ TITLE }}</title>
+ <id>{{ BASE_URL }}/post/{{ FILENAME }}/</id>
+ <updated>{{ DATE_FORMATTED }}</updated>
+ <published>{{ DATE_FORMATTED }}</published>
+ <link href="{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ FILENAME }}/" />
+ <author>
+ <name>{{ AUTHOR_NAME }}</name>
+ <email>{{ AUTHOR_EMAIL }}</email>
+ </author>
+ <content type="html"><![CDATA[{{ CONTENT }}]]></content>
+ </entry>
+ {% endblock %}
+</feed>
+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"
+grep "_build/post/post04/index\\.html" "${TEMP}/output.txt"
+grep "_build/post/post05/index\\.html" "${TEMP}/output.txt"
+grep "_build/post/post06/index\\.html" "${TEMP}/output.txt"
+grep "_build/post/post07/index\\.html" "${TEMP}/output.txt"
+grep "_build/post/post08/index\\.html" "${TEMP}/output.txt"
+grep "_build/post/post09/index\\.html" "${TEMP}/output.txt"
+grep "_build/post/post10/index\\.html" "${TEMP}/output.txt"
+grep "_build/post/post11/index\\.html" "${TEMP}/output.txt"
+
+rm "${TEMP}/output.txt"
+
+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/</id>
+ <updated>2016-09-11T00:00:00Z</updated>
+ <link href="http://example.org/" />
+ <link href="http://example.org/atom/" rel="self" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <subtitle type="text">WAT?!</subtitle>
+
+ <entry>
+ <title type="text">Post 11</title>
+ <id>/post/post11/</id>
+ <updated>2016-09-11T00:00:00Z</updated>
+ <published>2016-09-11T00:00:00Z</published>
+ <link href="http://example.org/post/post11/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 11.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 10</title>
+ <id>/post/post10/</id>
+ <updated>2016-09-10T00:00:00Z</updated>
+ <published>2016-09-10T00:00:00Z</published>
+ <link href="http://example.org/post/post10/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 10.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 09</title>
+ <id>/post/post09/</id>
+ <updated>2016-09-09T00:00:00Z</updated>
+ <published>2016-09-09T00:00:00Z</published>
+ <link href="http://example.org/post/post09/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 09.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 08</title>
+ <id>/post/post08/</id>
+ <updated>2016-09-08T00:00:00Z</updated>
+ <published>2016-09-08T00:00:00Z</published>
+ <link href="http://example.org/post/post08/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 08.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 07</title>
+ <id>/post/post07/</id>
+ <updated>2016-09-07T00:00:00Z</updated>
+ <published>2016-09-07T00:00:00Z</published>
+ <link href="http://example.org/post/post07/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 07.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 06</title>
+ <id>/post/post06/</id>
+ <updated>2016-09-06T00:00:00Z</updated>
+ <published>2016-09-06T00:00:00Z</published>
+ <link href="http://example.org/post/post06/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 06.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 05</title>
+ <id>/post/post05/</id>
+ <updated>2016-09-05T00:00:00Z</updated>
+ <published>2016-09-05T00:00:00Z</published>
+ <link href="http://example.org/post/post05/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 05.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 04</title>
+ <id>/post/post04/</id>
+ <updated>2016-09-04T00:00:00Z</updated>
+ <published>2016-09-04T00:00:00Z</published>
+ <link href="http://example.org/post/post04/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 04.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 03</title>
+ <id>/post/post03/</id>
+ <updated>2016-09-03T00:00:00Z</updated>
+ <published>2016-09-03T00:00:00Z</published>
+ <link href="http://example.org/post/post03/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 03.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 02</title>
+ <id>/post/post02/</id>
+ <updated>2016-09-02T00:00:00Z</updated>
+ <published>2016-09-02T00:00:00Z</published>
+ <link href="http://example.org/post/post02/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 02.</p>
+]]></content>
+ </entry>
+
+ <entry>
+ <title type="text">Post 01</title>
+ <id>/post/post01/</id>
+ <updated>2016-09-01T00:00:00Z</updated>
+ <published>2016-09-01T00:00:00Z</published>
+ <link href="http://example.org/post/post01/" />
+ <author>
+ <name>Lol</name>
+ <email>author@example.com</email>
+ </author>
+ <content type="html"><![CDATA[<p>This is Post 01.</p>
+]]></content>
+ </entry>
+
+</feed>
+EOF
+diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"
+
+rm -rf "${TEMP}/proj/_build"
+
+
### default settings with some posts, atom posts per page 0
cat > "${TEMP}/proj/blogcfile" <<EOF