aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blogc-make/ctx.c20
-rw-r--r--src/blogc-make/ctx.h1
-rw-r--r--src/blogc-make/rules.c41
-rw-r--r--src/blogc-make/settings.c3
4 files changed, 24 insertions, 41 deletions
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index c7d6ca9..e062474 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -130,13 +130,6 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
}
free(content);
- // fix output_dir, if forced from environment variable
- const char *output_dir_env = getenv("OUTPUT_DIR");
- if (output_dir_env != NULL) {
- bc_trie_insert(settings->settings, "output_dir",
- bc_strdup(output_dir_env));
- }
-
char *atom_template = bm_atom_deploy(settings, err);
if (*err != NULL) {
return NULL;
@@ -162,12 +155,15 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
rv->root_dir = realpath(dirname(real_filename), NULL);
free(real_filename);
- const char *output_dir = bc_trie_lookup(settings->settings, "output_dir");
- if (output_dir[0] == '/') {
- rv->output_dir = bc_strdup(output_dir);
+ const char *output_dir = getenv("OUTPUT_DIR");
+ rv->short_output_dir = bc_strdup(output_dir != NULL ? output_dir : "_build");
+
+ if (rv->short_output_dir[0] == '/') {
+ rv->output_dir = bc_strdup(rv->short_output_dir);
}
else {
- rv->output_dir = bc_strdup_printf("%s/%s", rv->root_dir, output_dir);
+ rv->output_dir = bc_strdup_printf("%s/%s", rv->root_dir,
+ rv->short_output_dir);
}
// can't return null and set error after this!
@@ -272,6 +268,8 @@ bm_ctx_free_internal(bm_ctx_t *ctx)
free(ctx->root_dir);
ctx->root_dir = NULL;
+ free(ctx->short_output_dir);
+ ctx->short_output_dir = NULL;
free(ctx->output_dir);
ctx->output_dir = NULL;
diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h
index 14e913f..962c029 100644
--- a/src/blogc-make/ctx.h
+++ b/src/blogc-make/ctx.h
@@ -52,6 +52,7 @@ typedef struct {
char *root_dir;
char *output_dir;
+ char *short_output_dir;
bm_filectx_t *main_template_fctx;
bm_filectx_t *atom_template_fctx;
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index 52afb2d..e9755a2 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -32,12 +32,10 @@ index_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
const char *html_ext = bc_trie_lookup(ctx->settings->settings,
"html_ext");
- const char *output_dir = bc_trie_lookup(ctx->settings->settings,
- "output_dir");
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", output_dir,
+ char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir,
is_index ? "" : "/", is_index ? "" : index_prefix,
html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
@@ -91,12 +89,11 @@ atom_outputlist(bm_ctx_t *ctx)
return NULL;
bc_slist_t *rv = NULL;
- const char *output_dir = bc_trie_lookup(ctx->settings->settings,
- "output_dir");
const char *atom_prefix = bc_trie_lookup(ctx->settings->settings,
"atom_prefix");
const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext");
- char *f = bc_strdup_printf("%s/%s%s", output_dir, atom_prefix, atom_ext);
+ char *f = bc_strdup_printf("%s/%s%s", ctx->short_output_dir,
+ atom_prefix, atom_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
free(f);
return rv;
@@ -148,14 +145,12 @@ atom_tags_outputlist(bm_ctx_t *ctx)
return NULL;
bc_slist_t *rv = NULL;
- const char *output_dir = bc_trie_lookup(ctx->settings->settings,
- "output_dir");
const char *atom_prefix = bc_trie_lookup(ctx->settings->settings,
"atom_prefix");
const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext");
for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) {
- char *f = bc_strdup_printf("%s/%s/%s%s", output_dir, atom_prefix,
- ctx->settings->tags[i], atom_ext);
+ char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir,
+ atom_prefix, ctx->settings->tags[i], atom_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
free(f);
}
@@ -218,8 +213,6 @@ pagination_outputlist(bm_ctx_t *ctx)
NULL, 10); // FIXME: improve
size_t pages = ceilf(((float) num_posts) / posts_per_page);
- const char *output_dir = bc_trie_lookup(ctx->settings->settings,
- "output_dir");
const char *pagination_prefix = bc_trie_lookup(ctx->settings->settings,
"pagination_prefix");
const char *html_ext = bc_trie_lookup(ctx->settings->settings,
@@ -227,8 +220,8 @@ pagination_outputlist(bm_ctx_t *ctx)
bc_slist_t *rv = NULL;
for (size_t i = 0; i < pages; i++) {
- char *f = bc_strdup_printf("%s/%s/%d%s", output_dir, pagination_prefix,
- i + 1, html_ext);
+ char *f = bc_strdup_printf("%s/%s/%d%s", ctx->short_output_dir,
+ pagination_prefix, i + 1, html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
free(f);
}
@@ -281,8 +274,6 @@ posts_outputlist(bm_ctx_t *ctx)
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
- const char *output_dir = bc_trie_lookup(ctx->settings->settings,
- "output_dir");
const char *post_prefix = bc_trie_lookup(ctx->settings->settings,
"post_prefix");
const char *html_ext = bc_trie_lookup(ctx->settings->settings,
@@ -290,8 +281,8 @@ posts_outputlist(bm_ctx_t *ctx)
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", output_dir, post_prefix,
- ctx->settings->posts[i], html_ext);
+ char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir,
+ post_prefix, ctx->settings->posts[i], html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
free(f);
}
@@ -346,14 +337,12 @@ tags_outputlist(bm_ctx_t *ctx)
return NULL;
bc_slist_t *rv = NULL;
- const char *output_dir = bc_trie_lookup(ctx->settings->settings,
- "output_dir");
const char *tag_prefix = bc_trie_lookup(ctx->settings->settings,
"tag_prefix");
const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext");
for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) {
- char *f = bc_strdup_printf("%s/%s/%s%s", output_dir, tag_prefix,
- ctx->settings->tags[i], html_ext);
+ char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir,
+ tag_prefix, ctx->settings->tags[i], html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
free(f);
}
@@ -411,15 +400,13 @@ pages_outputlist(bm_ctx_t *ctx)
if (ctx == NULL || ctx->settings->pages == NULL)
return NULL;
- const char *output_dir = bc_trie_lookup(ctx->settings->settings,
- "output_dir");
const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext");
bc_slist_t *rv = NULL;
for (size_t i = 0; ctx->settings->pages[i] != NULL; i++) {
bool is_index = (0 == strcmp(ctx->settings->pages[i], "index"))
&& (html_ext[0] == '/');
- char *f = bc_strdup_printf("%s%s%s%s", output_dir,
+ char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir,
is_index ? "" : "/", is_index ? "" : ctx->settings->pages[i],
html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
@@ -475,9 +462,9 @@ copy_outputlist(bm_ctx_t *ctx)
return NULL;
bc_slist_t *rv = NULL;
- const char *dir = bc_trie_lookup(ctx->settings->settings, "output_dir");
for (size_t i = 0; ctx->settings->copy[i] != NULL; i++) {
- char *f = bc_strdup_printf("%s/%s", dir, ctx->settings->copy[i]);
+ char *f = bc_strdup_printf("%s/%s", ctx->short_output_dir,
+ ctx->settings->copy[i]);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f));
free(f);
}
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index 3552223..c80feaa 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -27,9 +27,6 @@ static const struct default_settings_map {
{"main_template", "main.tmpl"},
{"source_ext", ".txt"},
- // output
- {"output_dir", "_build"},
-
// pagination
{"pagination_prefix", "page"},
{"posts_per_page", "10"},