diff options
author | Michael McVady <femtonaut@gmail.com> | 2021-11-18 14:37:19 -0500 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2021-11-18 14:37:19 -0500 |
commit | 659b6cdd8530e157cb8b5ea688933f13e3c6c12e (patch) | |
tree | c61765e229ae6b3e43acae724fa30e2dcd0805d6 | |
parent | 4f28d4e17d4eddeb7b27ccceee80a92233a7f0c7 (diff) |
Template posts
-rw-r--r-- | assets/post.html | 13 | ||||
-rw-r--r-- | src/clog.c | 20 |
2 files changed, 25 insertions, 8 deletions
diff --git a/assets/post.html b/assets/post.html new file mode 100644 index 0000000..80934c6 --- /dev/null +++ b/assets/post.html @@ -0,0 +1,13 @@ +<!-- begin post: {{ post.id }} --> +<div class="post"> +<hr class="hdiv"/> +<div class="head"> +<h2><span class="title">%s</span></h2> +<span class="date">{{ post.date_string }} <!-- {{ post.epoch }} --></span> +</div> +<div class="body"> +%s +</div> <!--body--> +<hr class="hdiv"/> +</div> +<!-- end post: {{ post.id }} --> @@ -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: ; |