aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2018-07-26 20:28:40 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2018-07-26 20:28:40 +0200
commit69caadbe08b27188ac0ab3bd0e49bf3ee4f8244c (patch)
tree649d90a7adc1513fd2fbd3a4114a13e8709f452c /src
parentcc963f2478aa88c4b6fdb0159eb3cc0580784823 (diff)
downloadblogc-69caadbe08b27188ac0ab3bd0e49bf3ee4f8244c.tar.gz
blogc-69caadbe08b27188ac0ab3bd0e49bf3ee4f8244c.tar.bz2
blogc-69caadbe08b27188ac0ab3bd0e49bf3ee4f8244c.zip
make: allow custom atom templates
Diffstat (limited to 'src')
-rw-r--r--src/blogc-make/ctx.c29
-rw-r--r--src/blogc-make/ctx.h1
-rw-r--r--src/blogc-make/settings.c1
3 files changed, 24 insertions, 7 deletions
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"},