From 659b6cdd8530e157cb8b5ea688933f13e3c6c12e Mon Sep 17 00:00:00 2001
From: Michael McVady <femtonaut@gmail.com>
Date: Thu, 18 Nov 2021 14:37:19 -0500
Subject: Template posts

---
 assets/post.html | 13 +++++++++++++
 src/clog.c       | 20 ++++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)
 create mode 100644 assets/post.html

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 }} -->
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