Mercurial > paster
comparison page.c @ 81:1ffe2f5a8500
pasterd: use HTML files to allow themes
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 17 Mar 2023 07:56:01 +0100 |
parents | 52029a52a385 |
children |
comparison
equal
deleted
inserted
replaced
80:9bc744a4a292 | 81:1ffe2f5a8500 |
---|---|
20 #include <string.h> | 20 #include <string.h> |
21 | 21 |
22 #include "config.h" | 22 #include "config.h" |
23 #include "page.h" | 23 #include "page.h" |
24 #include "util.h" | 24 #include "util.h" |
25 | |
26 #include "html/footer.h" | |
27 #include "html/header.h" | |
28 #include "html/status.h" | |
29 | |
30 #define CHAR(html) (const char *)(html) | |
31 | 25 |
32 enum { | 26 enum { |
33 KEYWORD_TITLE, | 27 KEYWORD_TITLE, |
34 }; | 28 }; |
35 | 29 |
61 | 55 |
62 void | 56 void |
63 page(struct kreq *req, | 57 page(struct kreq *req, |
64 enum khttp status, | 58 enum khttp status, |
65 const char *title, | 59 const char *title, |
66 const unsigned char *html, | 60 const char *filename, |
67 const struct ktemplate *tmpl) | 61 const struct ktemplate *tmpl) |
68 { | 62 { |
69 assert(req); | 63 assert(req); |
70 assert(title); | 64 assert(title); |
71 assert(html); | 65 assert(filename); |
72 assert(tmpl); | 66 assert(tmpl); |
73 | 67 |
74 struct page self = { | 68 struct page self = { |
75 .req = req, | 69 .req = req, |
76 .template = { | 70 .template = { |
83 }; | 77 }; |
84 | 78 |
85 khttp_head(req, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME_TEXT_HTML]); | 79 khttp_head(req, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME_TEXT_HTML]); |
86 khttp_head(req, kresps[KRESP_STATUS], "%s", khttps[status]); | 80 khttp_head(req, kresps[KRESP_STATUS], "%s", khttps[status]); |
87 khttp_body(req); | 81 khttp_body(req); |
88 khttp_template_buf(req, &self.template, CHAR(html_header), strlen(CHAR(html_header))); | 82 khttp_template(req, &self.template, path("header.html")); |
89 khttp_template_buf(req, tmpl, CHAR(html), strlen(CHAR(html))); | 83 khttp_template(req, tmpl, path(filename)); |
90 khttp_template_buf(req, NULL, CHAR(html_footer), strlen(CHAR(html_footer))); | 84 khttp_template(req, NULL, path("footer.html")); |
91 khttp_free(req); | 85 khttp_free(req); |
92 } | 86 } |