aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/blogcfile.5.ronn6
-rw-r--r--src/blogc-make/atom.c12
-rw-r--r--src/blogc-make/settings.c1
-rw-r--r--tests/blogc-make/check_atom.c128
4 files changed, 146 insertions, 1 deletions
diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn
index 61812a4..5f2406d 100644
--- a/man/blogcfile.5.ronn
+++ b/man/blogcfile.5.ronn
@@ -58,6 +58,12 @@ 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.13.11` blogc-make was generating "broken" entry IDs in the atom feeds.
+ This behavior was fixed in version `0.13.11` 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.
+
* `content_dir` (default: `content`):
The directory that stores the source files. This directory is relative
to `blogcfile`.
diff --git a/src/blogc-make/atom.c b/src/blogc-make/atom.c
index ae5e0c1..b953876 100644
--- a/src/blogc-make/atom.c
+++ b/src/blogc-make/atom.c
@@ -84,11 +84,21 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
char *post_url = bm_generate_filename(NULL, post_prefix, "{{ FILENAME }}",
post_ext);
+ char *entry_id = NULL;
+ if (bc_str_to_bool(bc_trie_lookup(settings->settings, "atom_legacy_entry_id"))) {
+ entry_id = bc_strdup_printf("%s%s/{{ FILENAME }}/",
+ post_prefix[0] == '\0' ? "" : "/", post_prefix);
+ }
+ else {
+ entry_id = bc_strdup(post_url);
+ }
+
char *content = bc_strdup_printf(atom_template, atom_url->str, atom_url->str,
- post_url, post_url);
+ entry_id, post_url);
bc_string_free(atom_url, true);
free(post_url);
+ free(entry_id);
if (-1 == write(fd, content, strlen(content))) {
*err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index 2029199..719afe1 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -43,6 +43,7 @@ static const struct default_settings_map {
{"atom_prefix", "atom"},
{"atom_ext", ".xml"},
{"atom_order", "DESC"},
+ {"atom_legacy_entry_id", NULL},
// generic
{"date_format", "%b %d, %Y, %I:%M %p GMT"},
diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c
index ac68e67..f58f2ba 100644
--- a/tests/blogc-make/check_atom.c
+++ b/tests/blogc-make/check_atom.c
@@ -269,6 +269,132 @@ test_atom_dir(void **state)
}
+static void
+test_atom_legacy_entry_id_empty(void **state)
+{
+ bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
+ settings->settings = bc_trie_new(free);
+ bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
+ bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
+ bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
+ bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
+ bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1"));
+
+ bc_error_t *err = NULL;
+ char *rv = bm_atom_deploy(settings, &err);
+
+ assert_non_null(rv);
+ assert_null(err);
+
+ size_t cmp_len;
+ char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+
+ assert_non_null(cmp);
+ assert_null(err);
+
+ assert_string_equal(cmp,
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
+ " <title type=\"text\">{{ SITE_TITLE }}{% ifdef FILTER_TAG %} - "
+ "{{ FILTER_TAG }}{% endif %}</title>\n"
+ " <id>{{ BASE_URL }}{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}"
+ "{% else %}/index{% endif %}.xml</id>\n"
+ " <updated>{{ DATE_FIRST_FORMATTED }}</updated>\n"
+ " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/\" />\n"
+ " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}{% ifdef FILTER_TAG %}"
+ "/{{ FILTER_TAG }}{% else %}/index{% endif %}.xml\" rel=\"self\" />\n"
+ " <author>\n"
+ " <name>{{ AUTHOR_NAME }}</name>\n"
+ " <email>{{ AUTHOR_EMAIL }}</email>\n"
+ " </author>\n"
+ " <subtitle type=\"text\">{{ SITE_TAGLINE }}</subtitle>\n"
+ " {% block listing %}\n"
+ " <entry>\n"
+ " <title type=\"text\">{{ TITLE }}</title>\n"
+ " <id>{{ BASE_URL }}/{{ FILENAME }}/</id>\n"
+ " <updated>{{ DATE_FORMATTED }}</updated>\n"
+ " <published>{{ DATE_FORMATTED }}</published>\n"
+ " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/{{ FILENAME }}.html\" />\n"
+ " <author>\n"
+ " <name>{{ AUTHOR_NAME }}</name>\n"
+ " <email>{{ AUTHOR_EMAIL }}</email>\n"
+ " </author>\n"
+ " <content type=\"html\"><![CDATA[{{ CONTENT }}]]></content>\n"
+ " </entry>\n"
+ " {% endblock %}\n"
+ "</feed>\n");
+
+ free(cmp);
+ bm_atom_destroy(rv);
+ free(rv);
+ bc_trie_free(settings->settings);
+ free(settings);
+}
+
+
+static void
+test_atom_legacy_entry_id(void **state)
+{
+ bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
+ settings->settings = bc_trie_new(free);
+ bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
+ bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
+ bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
+ bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
+ bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1"));
+
+ bc_error_t *err = NULL;
+ char *rv = bm_atom_deploy(settings, &err);
+
+ assert_non_null(rv);
+ assert_null(err);
+
+ size_t cmp_len;
+ char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+
+ assert_non_null(cmp);
+ assert_null(err);
+
+ assert_string_equal(cmp,
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
+ " <title type=\"text\">{{ SITE_TITLE }}{% ifdef FILTER_TAG %} - "
+ "{{ FILTER_TAG }}{% endif %}</title>\n"
+ " <id>{{ BASE_URL }}/atom{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}"
+ "{% endif %}.xml</id>\n"
+ " <updated>{{ DATE_FIRST_FORMATTED }}</updated>\n"
+ " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/\" />\n"
+ " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/atom{% ifdef FILTER_TAG %}"
+ "/{{ FILTER_TAG }}{% endif %}.xml\" rel=\"self\" />\n"
+ " <author>\n"
+ " <name>{{ AUTHOR_NAME }}</name>\n"
+ " <email>{{ AUTHOR_EMAIL }}</email>\n"
+ " </author>\n"
+ " <subtitle type=\"text\">{{ SITE_TAGLINE }}</subtitle>\n"
+ " {% block listing %}\n"
+ " <entry>\n"
+ " <title type=\"text\">{{ TITLE }}</title>\n"
+ " <id>{{ BASE_URL }}/post/{{ FILENAME }}/</id>\n"
+ " <updated>{{ DATE_FORMATTED }}</updated>\n"
+ " <published>{{ DATE_FORMATTED }}</published>\n"
+ " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/post/{{ FILENAME }}.html\" />\n"
+ " <author>\n"
+ " <name>{{ AUTHOR_NAME }}</name>\n"
+ " <email>{{ AUTHOR_EMAIL }}</email>\n"
+ " </author>\n"
+ " <content type=\"html\"><![CDATA[{{ CONTENT }}]]></content>\n"
+ " </entry>\n"
+ " {% endblock %}\n"
+ "</feed>\n");
+
+ free(cmp);
+ bm_atom_destroy(rv);
+ free(rv);
+ bc_trie_free(settings->settings);
+ free(settings);
+}
+
+
int
main(void)
{
@@ -277,6 +403,8 @@ main(void)
unit_test(test_atom_empty_dir),
unit_test(test_atom_file),
unit_test(test_atom_dir),
+ unit_test(test_atom_legacy_entry_id_empty),
+ unit_test(test_atom_legacy_entry_id),
};
return run_tests(tests);
}