From 659b6cdd8530e157cb8b5ea688933f13e3c6c12e Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Thu, 18 Nov 2021 14:37:19 -0500 Subject: Template posts --- src/clog.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/clog.c b/src/clog.c index 083e07d..c853fd3 100644 --- a/src/clog.c +++ b/src/clog.c @@ -67,7 +67,7 @@ page(struct http_request *req) * Now we can fire off the query, once it returns we either have * a result on which we can operate or an error occurred. */ - if (!kore_pgsql_query(&sql, "SELECT id, title, body FROM entries")) { + if (!kore_pgsql_query(&sql, "SELECT id, title, body FROM entries ORDER BY id ASC;")) { kore_pgsql_logerror(&sql); goto out; } @@ -75,25 +75,29 @@ page(struct http_request *req) // Iterate over the result and dump it to somewhere. rows = kore_pgsql_ntuples(&sql); for (row = 0; row < rows; row++) { + id = kore_pgsql_getvalue(&sql, row, 0); title = kore_pgsql_getvalue(&sql, row, 1); body = kore_pgsql_getvalue(&sql, row, 2); - - kore_log(LOG_NOTICE, "id: '%s'", id); - kore_log(LOG_NOTICE, "title: '%s'", title); - kore_log(LOG_NOTICE, "body: '%s'", body); + kore_log(LOG_NOTICE, "id: '%s'; title '%s'", id, title); struct kore_buf *html_buf = kore_buf_alloc(4096); + if (!render_md(body, html_buf)) { kore_log(LOG_ERR, "Error rendering markdown for entry %s.", id); kore_buf_free(html_buf); continue; } - kore_buf_append(resp_buf, asset_post_begin_html, asset_len_post_begin_html); - kore_buf_appendf(resp_buf, "%s", kore_buf_stringify(html_buf, NULL)); - kore_buf_append(resp_buf, asset_post_end_html, asset_len_post_end_html); + kore_buf_appendf( + resp_buf, + (const char *) asset_post_html, + title, + kore_buf_stringify(html_buf, NULL) + ); + kore_buf_free(html_buf); + } out: ; -- cgit v1.2.3