diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/loader.c | 20 | ||||
-rw-r--r-- | src/loader.h | 3 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/renderer.c | 36 | ||||
-rw-r--r-- | src/renderer.h | 2 |
5 files changed, 51 insertions, 12 deletions
diff --git a/src/loader.c b/src/loader.c index 485fb0d..87abd8e 100644 --- a/src/loader.c +++ b/src/loader.c @@ -124,10 +124,11 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err) b_slist_t* -blogc_source_parse_from_files(b_slist_t *l, blogc_error_t **err) +blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) { blogc_error_t *tmp_err = NULL; b_slist_t *rv = NULL; + bool first = true; for (b_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { char *f = tmp->data; @@ -142,6 +143,23 @@ blogc_source_parse_from_files(b_slist_t *l, blogc_error_t **err) rv = NULL; break; } + if (first) { + const char *val = b_trie_lookup(s, "DATE"); + if (val != NULL) + b_trie_insert(conf, "DATE_FIRST", b_strdup(val)); + val = b_trie_lookup(s, "FILENAME"); + if (val != NULL) + b_trie_insert(conf, "FILENAME_FIRST", b_strdup(val)); + first = false; + } + if (tmp->next == NULL) { // last + const char *val = b_trie_lookup(s, "DATE"); + if (val != NULL) + b_trie_insert(conf, "DATE_LAST", b_strdup(val)); + val = b_trie_lookup(s, "FILENAME"); + if (val != NULL) + b_trie_insert(conf, "FILENAME_LAST", b_strdup(val)); + } rv = b_slist_append(rv, s); } return rv; diff --git a/src/loader.h b/src/loader.h index 6407d0d..2b6b306 100644 --- a/src/loader.h +++ b/src/loader.h @@ -18,6 +18,7 @@ char* blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err char* blogc_get_filename(const char *f); b_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err); b_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err); -b_slist_t* blogc_source_parse_from_files(b_slist_t *l, blogc_error_t **err); +b_slist_t* blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, + blogc_error_t **err); #endif /* _LOADER_H */ @@ -208,7 +208,7 @@ main(int argc, char **argv) goto cleanup2; } - b_slist_t *s = blogc_source_parse_from_files(sources, &err); + b_slist_t *s = blogc_source_parse_from_files(config, sources, &err); if (err != NULL) { blogc_error_print(err); goto cleanup3; diff --git a/src/renderer.c b/src/renderer.c index ccd6c04..c73244b 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -39,9 +39,8 @@ blogc_get_variable(const char *name, b_trie_t *global, b_trie_t *local) char* -blogc_format_date(b_trie_t *global, b_trie_t *local) +blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local) { - const char *date = blogc_get_variable("DATE", global, local); const char *date_format = blogc_get_variable("DATE_FORMAT", global, local); if (date == NULL) return NULL; @@ -82,6 +81,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing b_trie_t *tmp_source = NULL; const char *config_value = NULL; + const char *config_var = NULL; char *config_value2 = NULL; unsigned int if_count = 0; @@ -143,9 +143,18 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing case BLOGC_TEMPLATE_VARIABLE_STMT: if (stmt->value != NULL) { - if (0 == strcmp(stmt->value, "DATE_FORMATTED")) { - config_value2 = blogc_format_date(config, - inside_block ? tmp_source : NULL); + config_var = NULL; + if (0 == strcmp(stmt->value, "DATE_FORMATTED")) + config_var = "DATE"; + else if (0 == strcmp(stmt->value, "DATE_FIRST_FORMATTED")) + config_var = "DATE_FIRST"; + else if (0 == strcmp(stmt->value, "DATE_LAST_FORMATTED")) + config_var = "DATE_LAST"; + if (config_var != NULL) { + config_value2 = blogc_format_date( + blogc_get_variable(config_var, config, + inside_block ? tmp_source : NULL), + config, inside_block ? tmp_source : NULL); if (config_value2 != NULL) { b_string_append(str, config_value2); free(config_value2); @@ -181,8 +190,18 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing case BLOGC_TEMPLATE_IF_STMT: defined = false; if (stmt->value != NULL) { - if (0 == strcmp(stmt->value, "DATE_FORMATTED")) { - config_value2 = blogc_format_date(config, tmp_source); + config_var = NULL; + if (0 == strcmp(stmt->value, "DATE_FORMATTED")) + config_var = "DATE"; + else if (0 == strcmp(stmt->value, "DATE_FIRST_FORMATTED")) + config_var = "DATE_FIRST"; + else if (0 == strcmp(stmt->value, "DATE_LAST_FORMATTED")) + config_var = "DATE_LAST"; + if (config_var != NULL) { + config_value2 = blogc_format_date( + blogc_get_variable(config_var, config, + inside_block ? tmp_source : NULL), + config, inside_block ? tmp_source : NULL); if (config_value2 != NULL) { defined = true; free(config_value2); @@ -190,7 +209,8 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing } } else - defined = blogc_get_variable(stmt->value, config, tmp_source) != NULL; + defined = blogc_get_variable(stmt->value, config, + inside_block ? tmp_source : NULL) != NULL; } if ((!if_not && !defined) || (if_not && defined)) { if_skip = if_count; diff --git a/src/renderer.h b/src/renderer.h index e4ad4a1..b6bbfed 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -13,7 +13,7 @@ #include "utils/utils.h" const char* blogc_get_variable(const char *name, b_trie_t *global, b_trie_t *local); -char* blogc_format_date(b_trie_t *global, b_trie_t *local); +char* blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local); char* blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing); |