ssnail

crappy and opinionated static site generator
git clone https://git.e1e0.net/ssnail.git
Log | Files | Refs | README | LICENSE

commit 1f7075c946aca465c649a85f1a3aa4df45c25a68
parent 14db6bf91c62b977b73a8386f8cbd75020fb0fcf
Author: Paco Esteban <paco@e1e0.net>
Date:   Thu,  2 Jul 2020 15:38:31 +0200

no need to set default values for metadata

we already initialize the struct.

Diffstat:
Mssnail.c | 32+++++++-------------------------
1 file changed, 7 insertions(+), 25 deletions(-)

diff --git a/ssnail.c b/ssnail.c @@ -274,49 +274,27 @@ gen_html(struct article *a) lowdown_buf(&opts, a->orig_content, strlen(a->orig_content), &a->html_content, &a->htmlz, &mq); - /* set default values for metadata */ - if ((a->title = strdup("")) == NULL) { - error = ssnail_error_from_errno("def title"); - goto out; - } - if ((a->author = strdup("")) == NULL) { - error = ssnail_error_from_errno("def author"); - goto out; - } - if ((a->date = strdup("")) == NULL) { - error = ssnail_error_from_errno("def date"); - goto out; - } - if ((a->type = strdup("page")) == NULL) { - error = ssnail_error_from_errno("def type"); - goto out; - } - /* collect metadata from markdown */ TAILQ_FOREACH(md, &mq, entries) { if (strcmp(md->key, "title") == 0 ) { - free(a->title); if ((a->title = strdup(md->value)) == NULL) { error = ssnail_error_from_errno("title"); goto out; } } if (strcmp(md->key, "author") == 0 ) { - free(a->author); if ((a->author = strdup(md->value)) == NULL) { error = ssnail_error_from_errno("author"); goto out; } } if (strcmp(md->key, "date") == 0 ) { - free(a->date); if ((a->date = strdup(md->value)) == NULL) { error = ssnail_error_from_errno("date"); goto out; } } if (strcmp(md->key, "type") == 0 ) { - free(a->type); if ((a->type = strdup(md->value)) == NULL) { error = ssnail_error_from_errno("type"); goto out; @@ -324,6 +302,12 @@ gen_html(struct article *a) } } + /* setup default type if not set */ + if ((a->type = strdup("page")) == NULL) { + error = ssnail_error_from_errno("def type"); + goto out; + } + out: lowdown_metaq_free(&mq); @@ -337,9 +321,7 @@ write_html(struct article *ap, char *head_tpl, char *foot_tpl) FILE *fout; char *header = NULL, *footer = NULL; - if (strlen(ap->title) == 0 - || strlen(ap->author) == 0 - || strlen(ap->date) == 0) { + if (ap->title == NULL || ap->author == NULL || ap->date == NULL) { error = ssnail_error_msg(2, "metadata"); goto out; }