diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-24 02:27:48 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-07-24 02:27:51 +0200 |
commit | c16c86bcc01dff2a984aeffd58e2402a876cc12d (patch) | |
tree | 7f2b3a6ea5951f7f684d550549069e0f1f0452f0 /src/blogc-make | |
parent | 355c8d37d0ce570e45fe8b905fee6417be35942e (diff) | |
download | blogc-c16c86bcc01dff2a984aeffd58e2402a876cc12d.tar.gz blogc-c16c86bcc01dff2a984aeffd58e2402a876cc12d.tar.bz2 blogc-c16c86bcc01dff2a984aeffd58e2402a876cc12d.zip |
make: handle empty prefixes properly
still needs to add integration tests
Diffstat (limited to 'src/blogc-make')
-rw-r--r-- | src/blogc-make/atom.c | 15 | ||||
-rw-r--r-- | src/blogc-make/ctx.c | 5 | ||||
-rw-r--r-- | src/blogc-make/rules.c | 22 | ||||
-rw-r--r-- | src/blogc-make/settings.c | 2 |
4 files changed, 26 insertions, 18 deletions
diff --git a/src/blogc-make/atom.c b/src/blogc-make/atom.c index d5f5387..0e4e631 100644 --- a/src/blogc-make/atom.c +++ b/src/blogc-make/atom.c @@ -20,11 +20,11 @@ static const char atom_template[] = "<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 }}/%s{%% ifdef FILTER_TAG %%}/{{ FILTER_TAG }}" + " <id>{{ BASE_URL }}%s%s{%% ifdef FILTER_TAG %%}/{{ FILTER_TAG }}" "{%% endif %%}%s</id>\n" " <updated>{{ DATE_FIRST_FORMATTED }}</updated>\n" " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/\" />\n" - " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/%s{%% ifdef FILTER_TAG %%}" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}%s%s{%% ifdef FILTER_TAG %%}" "/{{ FILTER_TAG }}{%% endif %%}%s\" rel=\"self\" />\n" " <author>\n" " <name>{{ AUTHOR_NAME }}</name>\n" @@ -34,10 +34,10 @@ static const char atom_template[] = " {%% block listing %%}\n" " <entry>\n" " <title type=\"text\">{{ TITLE }}</title>\n" - " <id>{{ BASE_URL }}/%s/{{ FILENAME }}/</id>\n" + " <id>{{ BASE_URL }}%s%s/{{ FILENAME }}/</id>\n" " <updated>{{ DATE_FORMATTED }}</updated>\n" " <published>{{ DATE_FORMATTED }}</published>\n" - " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}/%s/{{ FILENAME }}/\" />\n" + " <link href=\"{{ BASE_DOMAIN }}{{ BASE_URL }}%s%s/{{ FILENAME }}/\" />\n" " <author>\n" " <name>{{ AUTHOR_NAME }}</name>\n" " <email>{{ AUTHOR_EMAIL }}</email>\n" @@ -66,9 +66,12 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err) const char *atom_prefix = bc_trie_lookup(settings->settings, "atom_prefix"); const char *atom_ext = bc_trie_lookup(settings->settings, "atom_ext"); const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix"); + const char *atom_slash = atom_prefix[0] == '\0' ? "" : "/"; + const char *post_slash = post_prefix[0] == '\0' ? "" : "/"; - char *content = bc_strdup_printf(atom_template, atom_prefix, atom_ext, - atom_prefix, atom_ext, post_prefix, post_prefix); + char *content = bc_strdup_printf(atom_template, atom_slash, atom_prefix, + atom_ext, atom_slash, atom_prefix, atom_ext, post_slash, post_prefix, + post_slash, post_prefix); if (-1 == write(fd, content, strlen(content))) { *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM, diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c index 0a3f9a0..0c47c12 100644 --- a/src/blogc-make/ctx.c +++ b/src/blogc-make/ctx.c @@ -234,12 +234,13 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, const char *content_dir = bc_trie_lookup(settings->settings, "content_dir"); const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix"); const char *source_ext = bc_trie_lookup(settings->settings, "source_ext"); + const char *slash = post_prefix[0] == '\0' ? "" : "/"; rv->posts_fctx = NULL; if (settings->posts != NULL) { for (size_t i = 0; settings->posts[i] != NULL; i++) { - char *f = bc_strdup_printf("%s/%s/%s%s", content_dir, post_prefix, - settings->posts[i], source_ext); + char *f = bc_strdup_printf("%s%s%s/%s%s", content_dir, slash, + post_prefix, settings->posts[i], source_ext); rv->posts_fctx = bc_slist_append(rv->posts_fctx, bm_filectx_new(rv, f, settings->posts[i], NULL)); free(f); diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c index 8851313..2f4b119 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -82,10 +82,9 @@ index_outputlist(bm_ctx_t *ctx) "html_ext"); const char *index_prefix = bc_trie_lookup(ctx->settings->settings, "index_prefix"); - bool is_index = (index_prefix == NULL) && (html_ext[0] == '/'); - char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, - is_index ? "" : "/", is_index ? "" : index_prefix, - html_ext); + const char *slash = index_prefix[0] == '\0' && html_ext[0] == '/' ? "" : "/"; + char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, slash, + index_prefix, html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); return rv; @@ -141,8 +140,9 @@ atom_outputlist(bm_ctx_t *ctx) bc_slist_t *rv = NULL; const char *atom_prefix = bc_trie_lookup(ctx->settings->settings, "atom_prefix"); + const char *slash = atom_prefix[0] == '\0' ? "" : "/"; const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext"); - char *f = bc_strdup_printf("%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, slash, atom_prefix, atom_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -199,8 +199,9 @@ atom_tags_outputlist(bm_ctx_t *ctx) const char *atom_prefix = bc_trie_lookup(ctx->settings->settings, "atom_prefix"); const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext"); + const char *slash = atom_prefix[0] == '\0' ? "" : "/"; for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) { - char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%s%s", ctx->short_output_dir, slash, atom_prefix, ctx->settings->tags[i], atom_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -271,10 +272,11 @@ pagination_outputlist(bm_ctx_t *ctx) "pagination_prefix"); const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext"); + const char *slash = pagination_prefix[0] == '\0' ? "" : "/"; bc_slist_t *rv = NULL; for (size_t i = 0; i < pages; i++) { - char *f = bc_strdup_printf("%s/%s/%d%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%d%s", ctx->short_output_dir, slash, pagination_prefix, i + 1, html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -335,10 +337,11 @@ posts_outputlist(bm_ctx_t *ctx) "post_prefix"); const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext"); + const char *slash = post_prefix[0] == '\0' ? "" : "/"; bc_slist_t *rv = NULL; for (size_t i = 0; ctx->settings->posts[i] != NULL; i++) { - char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%s%s", ctx->short_output_dir, slash, post_prefix, ctx->settings->posts[i], html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -405,8 +408,9 @@ tags_outputlist(bm_ctx_t *ctx) const char *tag_prefix = bc_trie_lookup(ctx->settings->settings, "tag_prefix"); const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext"); + const char *slash = tag_prefix[0] == '\0' ? "" : "/"; for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) { - char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%s%s", ctx->short_output_dir, slash, tag_prefix, ctx->settings->tags[i], html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c index 9e24d41..2029199 100644 --- a/src/blogc-make/settings.c +++ b/src/blogc-make/settings.c @@ -34,7 +34,7 @@ static const struct default_settings_map { // html {"html_ext", "/index.html"}, - {"index_prefix", NULL}, + {"index_prefix", ""}, {"post_prefix", "post"}, {"tag_prefix", "tag"}, {"html_order", "DESC"}, |