From 1936b3a5d438fb7ab38f62978c9fd58c75e337f5 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Thu, 18 Jul 2019 18:21:35 -0400 Subject: make blog entries actually html --- blog.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/blog.c b/blog.c index 026017d..950ad5e 100644 --- a/blog.c +++ b/blog.c @@ -10,10 +10,24 @@ #include +#define DOCTYPE "\n" +#define HTML "\n" +#define META "\n" +#define TITLE "%s\n" +#define ICON "\n" +#define STYLE "\n" +#define BODY "\n\n" + +#define HTML_HEAD DOCTYPE HTML META TITLE ICON STYLE BODY + +#define HTML_TAIL "\n\n" + int handle_post(void) { + /* printf("Status: 200 OK\r\n"); printf("Content-Type: text/plain\r\n\r\n"); + */ read_post_data(); if (!authenticate(find_post_data("username"), find_post_data("password"))) { @@ -54,13 +68,15 @@ int handle_post(void) char *body = find_post_data("body"); if (body == NULL) { - puts("body is null?!"); + return 1; } + dprintf(newpost, HTML_HEAD, title); if (write(newpost, body, strlen(body)) != strlen(body)) { printf("write: %s\n", strerror(errno)); return 0; } + dprintf(newpost, HTML_TAIL); close(newpost); close(blogdir); @@ -80,14 +96,8 @@ int main(void) printf("Status: 200 OK\r\n"); printf("Content-Type: text/html\r\n\r\n"); - puts(""); - puts(""); - puts(""); - puts("Jakob Kaivo/blog"); - puts(""); - puts(""); - puts(""); - puts(""); + printf(HTML_HEAD, "new blog entry"); + printf("
\n", getenv("DOCUMENT_URI")); puts("
"); puts("
"); @@ -95,8 +105,8 @@ int main(void) puts("
"); puts(""); puts("
"); - puts(""); - puts(""); + + printf(HTML_TAIL); return 0; } -- cgit v1.2.1