summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blogc-make/atom.c10
-rw-r--r--src/blogc-make/ctx.c8
-rw-r--r--src/blogc-make/rules.c42
-rw-r--r--src/blogc-make/settings.c1
-rw-r--r--src/blogc-make/utils.c18
-rw-r--r--src/blogc-make/utils.h8
6 files changed, 55 insertions, 32 deletions
diff --git a/src/blogc-make/atom.c b/src/blogc-make/atom.c
index baf5eeb..f9e6294 100644
--- a/src/blogc-make/atom.c
+++ b/src/blogc-make/atom.c
@@ -48,6 +48,7 @@ bm_atom_generate(bm_settings_t *settings)
if (settings == NULL)
return NULL;
+ const char *blog_prefix = bc_trie_lookup(settings->settings, "blog_prefix");
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");
@@ -55,6 +56,11 @@ bm_atom_generate(bm_settings_t *settings)
bc_string_t *atom_url = bc_string_new();
+ if (blog_prefix != NULL) {
+ bc_string_append_c(atom_url, '/');
+ bc_string_append_printf(atom_url, blog_prefix);
+ }
+
if (atom_prefix[0] != '\0')
bc_string_append_c(atom_url, '/');
@@ -67,8 +73,8 @@ bm_atom_generate(bm_settings_t *settings)
bc_string_append(atom_url, "{% endif %}");
bc_string_append(atom_url, atom_ext);
- char *post_url = bm_generate_filename(NULL, post_prefix, "{{ FILENAME }}",
- post_ext);
+ char *post_url = bm_generate_filename(NULL, blog_prefix, post_prefix,
+ "{{ FILENAME }}", post_ext);
char *rv = bc_strdup_printf(atom_template, atom_url->str, atom_url->str,
post_url, post_url);
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index 0745529..8bc7e64 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -251,13 +251,15 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
free(atom_template);
const char *content_dir = bm_ctx_settings_lookup(rv, "content_dir");
+ const char *blog_prefix = bm_ctx_settings_lookup(rv, "blog_prefix");
const char *post_prefix = bm_ctx_settings_lookup(rv, "post_prefix");
const char *source_ext = bm_ctx_settings_lookup(rv, "source_ext");
const char *listing_entry = bm_ctx_settings_lookup(rv, "listing_entry");
rv->listing_entry_fctx = NULL;
if (listing_entry != NULL) {
- char *f = bm_generate_filename(content_dir, NULL, listing_entry, source_ext);
+ char *f = bm_generate_filename(content_dir, blog_prefix, NULL,
+ listing_entry, source_ext);
rv->listing_entry_fctx = bm_filectx_new(rv, f, listing_entry, NULL);
free(f);
}
@@ -265,7 +267,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
rv->posts_fctx = NULL;
if (settings->posts != NULL) {
for (size_t i = 0; settings->posts[i] != NULL; i++) {
- char *f = bm_generate_filename(content_dir, post_prefix,
+ char *f = bm_generate_filename(content_dir, blog_prefix, 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));
@@ -276,7 +278,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
rv->pages_fctx = NULL;
if (settings->pages != NULL) {
for (size_t i = 0; settings->pages[i] != NULL; i++) {
- char *f = bm_generate_filename(content_dir, NULL, settings->pages[i],
+ char *f = bm_generate_filename(content_dir, NULL, NULL, settings->pages[i],
source_ext);
rv->pages_fctx = bc_slist_append(rv->pages_fctx,
bm_filectx_new(rv, f, settings->pages[i], NULL));
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index 9cfc969..f50ec75 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -77,11 +77,12 @@ index_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *index_prefix = bm_ctx_settings_lookup(ctx, "index_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
- char *f = bm_generate_filename(ctx->short_output_dir, index_prefix, NULL,
- html_ext);
+ char *f = bm_generate_filename(ctx->short_output_dir, blog_prefix, index_prefix,
+ NULL, html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
@@ -137,11 +138,12 @@ atom_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *atom_prefix = bm_ctx_settings_lookup(ctx, "atom_prefix");
const char *atom_ext = bm_ctx_settings_lookup(ctx, "atom_ext");
- char *f = bm_generate_filename(ctx->short_output_dir, atom_prefix, NULL,
- atom_ext);
+ char *f = bm_generate_filename(ctx->short_output_dir, blog_prefix, atom_prefix,
+ NULL, atom_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
@@ -197,12 +199,13 @@ atom_tags_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *atom_prefix = bm_ctx_settings_lookup(ctx, "atom_prefix");
const char *atom_ext = bm_ctx_settings_lookup(ctx, "atom_ext");
for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) {
- char *f = bm_generate_filename(ctx->short_output_dir, atom_prefix,
- ctx->settings->tags[i], atom_ext);
+ char *f = bm_generate_filename(ctx->short_output_dir, blog_prefix,
+ atom_prefix, ctx->settings->tags[i], atom_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -278,13 +281,14 @@ pagination_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *pagination_prefix = bm_ctx_settings_lookup(ctx, "pagination_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
for (size_t i = 0; i < pages; i++) {
char *j = bc_strdup_printf("%d", i + 1);
- char *f = bm_generate_filename(ctx->short_output_dir, pagination_prefix,
- j, html_ext);
+ char *f = bm_generate_filename(ctx->short_output_dir, blog_prefix,
+ pagination_prefix, j, html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(j);
free(f);
@@ -348,6 +352,7 @@ pagination_tags_outputlist(bm_ctx_t *ctx)
bc_trie_t *variables = bc_trie_new(free);
posts_pagination(ctx, variables, "posts_per_page");
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *tag_prefix = bm_ctx_settings_lookup(ctx, "tag_prefix");
const char *pagination_prefix = bm_ctx_settings_lookup(ctx, "pagination_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
@@ -371,8 +376,8 @@ pagination_tags_outputlist(bm_ctx_t *ctx)
for (size_t i = 0; i < pages; i++) {
char *j = bc_strdup_printf("%d", i + 1);
- char *f = bm_generate_filename2(ctx->short_output_dir, tag_prefix,
- ctx->settings->tags[k], pagination_prefix, j, html_ext);
+ char *f = bm_generate_filename2(ctx->short_output_dir, blog_prefix,
+ tag_prefix, ctx->settings->tags[k], pagination_prefix, j, html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(j);
free(f);
@@ -404,6 +409,7 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bc_trie_insert(variables, "MAKE_RULE", bc_strdup("pagination_tags"));
bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *tag_prefix = bm_ctx_settings_lookup(ctx, "tag_prefix");
const char *pagination_prefix = bm_ctx_settings_lookup(ctx, "pagination_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
@@ -423,8 +429,8 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// amount of output pages
for (size_t k = 1; k <= bc_slist_length(outputs); k++) {
char *j = bc_strdup_printf("%d", k);
- char *f = bm_generate_filename2(ctx->short_output_dir, tag_prefix,
- ctx->settings->tags[i], pagination_prefix, j, html_ext);
+ char *f = bm_generate_filename2(ctx->short_output_dir, blog_prefix,
+ tag_prefix, ctx->settings->tags[i], pagination_prefix, j, html_ext);
free(j);
if (0 == strcmp(fctx->short_path, f)) {
tag = ctx->settings->tags[i];
@@ -470,12 +476,13 @@ posts_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *post_prefix = bm_ctx_settings_lookup(ctx, "post_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
for (size_t i = 0; ctx->settings->posts[i] != NULL; i++) {
- char *f = bm_generate_filename(ctx->short_output_dir, post_prefix,
- ctx->settings->posts[i], html_ext);
+ char *f = bm_generate_filename(ctx->short_output_dir, blog_prefix,
+ post_prefix, ctx->settings->posts[i], html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -540,12 +547,13 @@ tags_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
+ const char *blog_prefix = bm_ctx_settings_lookup(ctx, "blog_prefix");
const char *tag_prefix = bm_ctx_settings_lookup(ctx, "tag_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) {
- char *f = bm_generate_filename(ctx->short_output_dir, tag_prefix,
- ctx->settings->tags[i], html_ext);
+ char *f = bm_generate_filename(ctx->short_output_dir, blog_prefix,
+ tag_prefix, ctx->settings->tags[i], html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -608,7 +616,7 @@ pages_outputlist(bm_ctx_t *ctx)
for (size_t i = 0; ctx->settings->pages[i] != NULL; i++) {
char *f = bm_generate_filename(ctx->short_output_dir, NULL,
- ctx->settings->pages[i], html_ext);
+ NULL, ctx->settings->pages[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 4accc6d..2b78177 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -36,6 +36,7 @@ static const struct default_settings_map {
{"post_prefix", "post"},
{"tag_prefix", "tag"},
{"html_order", "DESC"},
+ {"blog_prefix", NULL},
// atom
{"atom_prefix", "atom"},
diff --git a/src/blogc-make/utils.c b/src/blogc-make/utils.c
index c987cfd..873aed1 100644
--- a/src/blogc-make/utils.c
+++ b/src/blogc-make/utils.c
@@ -15,9 +15,10 @@
char*
-bm_generate_filename(const char *dir, const char *prefix, const char *fname,
- const char *ext)
+bm_generate_filename(const char *dir, const char *gprefix, const char *prefix,
+ const char *fname, const char *ext)
{
+ bool have_gprefix = gprefix != NULL && gprefix[0] != '\0';
bool have_prefix = prefix != NULL && prefix[0] != '\0';
bool have_fname = fname != NULL && fname[0] != '\0';
bool have_ext = ext != NULL && ext[0] != '\0';
@@ -27,9 +28,14 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname,
bc_string_t *rv = bc_string_new();
- if (dir != NULL && (have_prefix || have_fname || have_ext))
+ if (dir != NULL && (have_gprefix || have_prefix || have_fname || have_ext))
bc_string_append(rv, dir);
+ if (have_gprefix) {
+ bc_string_append(rv, "/");
+ bc_string_append(rv, gprefix);
+ }
+
if ((have_prefix || have_fname || have_ext_noslash) && !is_index)
bc_string_append_c(rv, '/');
@@ -65,8 +71,8 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname,
char*
-bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
- const char *prefix2, const char *fname2, const char *ext)
+bm_generate_filename2(const char *dir, const char *gprefix, const char *prefix,
+ const char *fname, const char *prefix2, const char *fname2, const char *ext)
{
bool have_prefix = prefix != NULL && prefix[0] != '\0';
bool have_fname = fname != NULL && fname[0] != '\0';
@@ -89,7 +95,7 @@ bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
if (have_prefix2)
bc_string_append(p, prefix2);
- char *rv = bm_generate_filename(dir, p->str, fname2, ext);
+ char *rv = bm_generate_filename(dir, gprefix, p->str, fname2, ext);
bc_string_free(p, true);
return rv;
diff --git a/src/blogc-make/utils.h b/src/blogc-make/utils.h
index 801bf0f..13cb754 100644
--- a/src/blogc-make/utils.h
+++ b/src/blogc-make/utils.h
@@ -5,8 +5,8 @@
#include "../common/error.h"
-char* bm_generate_filename(const char *dir, const char *prefix, const char *fname,
- const char *ext);
-char* bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
- const char *prefix2, const char *fname2, const char *ext);
+char* bm_generate_filename(const char *dir, const char *gprefix, const char *prefix,
+ const char *fname, const char *ext);
+char* bm_generate_filename2(const char *dir, const char *gprefix, const char *prefix,
+ const char *fname, const char *prefix2, const char *fname2, const char *ext);
char* bm_abspath(const char *path, bc_error_t **err);