aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2021-11-18 14:37:19 -0500
committerMichael McVady <femtonaut@gmail.com>2021-11-18 14:37:19 -0500
commit659b6cdd8530e157cb8b5ea688933f13e3c6c12e (patch)
treec61765e229ae6b3e43acae724fa30e2dcd0805d6 /src
parent4f28d4e17d4eddeb7b27ccceee80a92233a7f0c7 (diff)
Template posts
Diffstat (limited to 'src')
-rw-r--r--src/clog.c20
1 files changed, 12 insertions, 8 deletions
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: ;