diff options
author | Michael McVady <femtonaut@gmail.com> | 2023-02-21 22:41:03 -0600 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2023-02-21 22:41:03 -0600 |
commit | 0b7bfb198191e1d4e4f74046662c7c48edd61b0d (patch) | |
tree | c7b21c211b3b143513e817b073602da5c3b77c3d | |
parent | bc18c974d647c439bbfc9cb32388e22a71e13438 (diff) |
Add title link to posts
-rw-r--r-- | assets/post.html | 2 | ||||
-rw-r--r-- | src/clog.c | 51 | ||||
-rw-r--r-- | src/init.c | 6 |
3 files changed, 20 insertions, 39 deletions
diff --git a/assets/post.html b/assets/post.html index a199fd6..25dd7fb 100644 --- a/assets/post.html +++ b/assets/post.html @@ -2,7 +2,7 @@ <div class="post"> <hr class="hdiv"/> <div class="head"> -<h2><span class="title">%s</span></h2> +<h2><span class="title"><a href="/posts/%s">%s</a></span></h2> <span class="date">%s</span> </div> <div class="body"> @@ -86,8 +86,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq); static void process_md_output(const MD_CHAR *, MD_SIZE size, void *); static int render_md(const char *, struct kore_buf *); -void -post_query_init(struct post_query *pq, enum content_type type, const char *id) { +void post_query_init(struct post_query *pq, enum content_type type, const char *id) { if (id != NULL) pq->id = kore_strdup(id); else @@ -99,8 +98,7 @@ post_query_init(struct post_query *pq, enum content_type type, const char *id) { pq->result = kore_buf_alloc(0); } -void -post_query_cleanup(struct post_query *pq) { +void post_query_cleanup(struct post_query *pq) { if (pq->id != NULL) kore_free((void *) pq->id); pq->id = NULL; @@ -110,8 +108,7 @@ post_query_cleanup(struct post_query *pq) { pq->result = NULL; } -int -validate_uuid(const char *uuid) { +int validate_uuid(const char *uuid) { int i = 0; if (strlen(uuid) != 36) @@ -135,8 +132,7 @@ validate_uuid(const char *uuid) { return KORE_RESULT_OK; } -enum content_type -get_content_type(struct http_request *req) { +enum content_type get_content_type(struct http_request *req) { int err = 0; const char *accept = NULL; @@ -151,8 +147,7 @@ get_content_type(struct http_request *req) { return HTML; } -int -http_ok_resp( +int http_ok_resp( struct http_request *req, enum content_type type, enum http_status_code status, @@ -191,8 +186,7 @@ http_ok_resp( return KORE_RESULT_OK; } -int -http_err_resp( +int http_err_resp( struct http_request *req, enum content_type type, enum http_status_code status @@ -229,17 +223,14 @@ http_err_resp( return KORE_RESULT_OK; } - -int -redirect(struct http_request *req) { +int redirect(struct http_request *req) { http_response_header(req, "Location", "/"); http_response(req, HTTP_STATUS_MOVED_PERMANENTLY, NULL, 0); return KORE_RESULT_OK; } -int -get_posts(struct http_request *req) { +int get_posts(struct http_request *req) { struct post_query pq; post_query_init(&pq, get_content_type(req), NULL); @@ -255,8 +246,7 @@ get_posts(struct http_request *req) { return KORE_RESULT_OK; } -int -get_posts_resource(struct http_request *req) { +int get_posts_resource(struct http_request *req) { int err = 0; struct post_query pq; @@ -287,8 +277,7 @@ out: ; return KORE_RESULT_OK; } -int -post_posts(struct http_request *req) { +int post_posts(struct http_request *req) { int err = 0; int status = HTTP_STATUS_CREATED; @@ -364,8 +353,7 @@ out: ; return KORE_RESULT_OK; } -int -sql_select_posts(struct post_query *pq) { +int sql_select_posts(struct post_query *pq) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -427,8 +415,7 @@ out: ; return err; } -int -delete_posts_resource(struct http_request *req) { +int delete_posts_resource(struct http_request *req) { int err = 0; enum content_type type = get_content_type(req); @@ -508,6 +495,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { kore_buf_appendf( pq->result, (const char *) asset_post_html, + id, title, created_at, kore_buf_stringify(html_buf, NULL) @@ -520,8 +508,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { return KORE_RESULT_OK; } -int -sql_insert_posts(const char *id, const char *title, const char *body) { +int sql_insert_posts(const char *id, const char *title, const char *body) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -554,8 +541,7 @@ out: ; return err; } -int -sql_delete_posts(const char *id) { +int sql_delete_posts(const char *id) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -586,8 +572,7 @@ out: ; return err; } -static int -render_md(const char *in, struct kore_buf *out) { +static int render_md(const char *in, struct kore_buf *out) { // Not a kore err. int err = 0; @@ -611,12 +596,10 @@ render_md(const char *in, struct kore_buf *out) { return KORE_RESULT_OK; } -static void -process_md_output(const MD_CHAR *html, MD_SIZE size, void *buf) { +static void process_md_output(const MD_CHAR *html, MD_SIZE size, void *buf) { kore_buf_append( (struct kore_buf *) buf, (const void *) html, (size_t) size ); } - @@ -6,8 +6,7 @@ void kore_parent_configure(int, char **); static const char *database = "db"; -void -kore_parent_configure(int argc, char **argv) { +void kore_parent_configure(int argc, char **argv) { int err = 0; kore_default_getopt(argc, argv); @@ -19,8 +18,7 @@ kore_parent_configure(int argc, char **argv) { } } -int -init_db(void) { +int init_db(void) { int err = 0; const char *pg_config = NULL; |