diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-02-14 23:51:36 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2017-02-14 23:51:36 +0100 |
commit | 80017f034146b50fdc441c96636f1098adf7037e (patch) | |
tree | cbac45bca69cf635c2ad633ea1bcd6f40ba97a9f /src/blogc/source-parser.c | |
parent | 99ef1c93f0359741fd18217cd81cf2c3e0beaf7b (diff) | |
download | blogc-80017f034146b50fdc441c96636f1098adf7037e.tar.gz blogc-80017f034146b50fdc441c96636f1098adf7037e.tar.bz2 blogc-80017f034146b50fdc441c96636f1098adf7037e.zip |
content-parser: source-parser: extract TITLE from content header
this patch implements support to using the first header found in source
file as the TITLE variable. please note that if the TITLE variable is
defined on the source file's variable section it takes precedence.
this patch changes the old behaviour and can break some users' websites.
if you have some '{% ifdef TITLE %}' blocks in your template, they will
evaluate to true if you don't defined TITLE manually, but have a header
in your content.
Diffstat (limited to 'src/blogc/source-parser.c')
-rw-r--r-- | src/blogc/source-parser.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/blogc/source-parser.c b/src/blogc/source-parser.c index a3d1e09..f6f3471 100644 --- a/src/blogc/source-parser.c +++ b/src/blogc/source-parser.c @@ -150,8 +150,21 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err) if (current == (src_len - 1)) { tmp = bc_strndup(src + start, src_len - start); bc_trie_insert(rv, "RAW_CONTENT", tmp); + char *title = NULL; char *description = NULL; - content = blogc_content_parse(tmp, &end_excerpt, &description); + content = blogc_content_parse(tmp, &end_excerpt, &title, + &description); + if (title != NULL) { + // do not override source-provided title. + if (NULL == bc_trie_lookup(rv, "TITLE")) { + // no need to free, because we are transfering memory + // ownership to the trie. + bc_trie_insert(rv, "TITLE", title); + } + else { + free(title); + } + } if (description != NULL) { // do not override source-provided description. if (NULL == bc_trie_lookup(rv, "DESCRIPTION")) { |