aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc/content-parser.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2017-02-14 23:51:36 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2017-02-14 23:51:36 +0100
commit80017f034146b50fdc441c96636f1098adf7037e (patch)
treecbac45bca69cf635c2ad633ea1bcd6f40ba97a9f /src/blogc/content-parser.c
parent99ef1c93f0359741fd18217cd81cf2c3e0beaf7b (diff)
downloadblogc-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/content-parser.c')
-rw-r--r--src/blogc/content-parser.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/blogc/content-parser.c b/src/blogc/content-parser.c
index 23586bb..415e5ee 100644
--- a/src/blogc/content-parser.c
+++ b/src/blogc/content-parser.c
@@ -674,7 +674,8 @@ blogc_is_ordered_list_item(const char *str, size_t prefix_len)
char*
-blogc_content_parse(const char *src, size_t *end_excerpt, char **description)
+blogc_content_parse(const char *src, size_t *end_excerpt, char **title,
+ char **description)
{
// src is always nul-terminated.
size_t src_len = strlen(src);
@@ -834,6 +835,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description)
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
tmp = bc_strndup(src + start, end - start);
+ if (title != NULL && *title == NULL)
+ *title = bc_strdup(tmp);
parsed = blogc_content_parse_inline(tmp);
slug = blogc_slugify(tmp);
if (slug == NULL)
@@ -915,10 +918,10 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description)
for (bc_slist_t *l = lines; l != NULL; l = l->next)
bc_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
- // do not propagate description to blockquote parsing,
+ // do not propagate title and description to blockquote parsing,
// because we just want paragraphs from first level of
// content.
- tmp = blogc_content_parse(tmp_str->str, NULL, NULL);
+ tmp = blogc_content_parse(tmp_str->str, NULL, NULL, NULL);
bc_string_append_printf(rv, "<blockquote>%s</blockquote>%s",
tmp, line_ending);
free(tmp);