aboutsummaryrefslogtreecommitdiffstats
path: root/src/source-parser.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-04-20 02:50:20 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-04-20 02:50:20 +0200
commit9b2a563b4931ca39cd6dd14bf85cda627714a4b2 (patch)
treeafcc5ead7219b0f9f38728eb58c88dfe641325dc /src/source-parser.c
parentc216deff59e2c0dd9538ced99d6b579013b3b5de (diff)
downloadblogc-9b2a563b4931ca39cd6dd14bf85cda627714a4b2.tar.gz
blogc-9b2a563b4931ca39cd6dd14bf85cda627714a4b2.tar.bz2
blogc-9b2a563b4931ca39cd6dd14bf85cda627714a4b2.zip
content-parser: extract post description from content
description is the first line of the first paragraph parsed from content file. users can override it declaring DESCRIPTION variable in source file itself. this also fixes a bug with line endings when using single line blockquotes.
Diffstat (limited to 'src/source-parser.c')
-rw-r--r--src/source-parser.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/source-parser.c b/src/source-parser.c
index 1047f06..6e026d2 100644
--- a/src/source-parser.c
+++ b/src/source-parser.c
@@ -154,7 +154,19 @@ blogc_source_parse(const char *src, size_t src_len, sb_error_t **err)
if (current == (src_len - 1)) {
tmp = sb_strndup(src + start, src_len - start);
sb_trie_insert(rv, "RAW_CONTENT", tmp);
- content = blogc_content_parse(tmp, &end_excerpt);
+ char *description = NULL;
+ content = blogc_content_parse(tmp, &end_excerpt, &description);
+ if (description != NULL) {
+ // do not override source-provided description.
+ if (NULL == sb_trie_lookup(rv, "DESCRIPTION")) {
+ // no need to free, because we are transfering memory
+ // ownership to the trie.
+ sb_trie_insert(rv, "DESCRIPTION", description);
+ }
+ else {
+ free(description);
+ }
+ }
sb_trie_insert(rv, "CONTENT", content);
sb_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
sb_strdup(content) : sb_strndup(content, end_excerpt));