From 212bd22001b24023a72342fd17a04a4cc24ae305 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Fri, 22 Dec 2023 11:59:54 -0600 Subject: Hack in form --- assets/error.json | 1 - assets/form.html | 20 +++++ assets/form_begin.html | 11 +++ assets/form_end.html | 9 ++ assets/static/css/retro.css | 200 ++++++++++++++++++++++++++++++++++++++++++++ conf/clog.conf | 4 +- src/clog.c | 31 +++++-- 7 files changed, 265 insertions(+), 11 deletions(-) delete mode 100644 assets/error.json create mode 100644 assets/form.html create mode 100644 assets/form_begin.html create mode 100644 assets/form_end.html create mode 100644 assets/static/css/retro.css diff --git a/assets/error.json b/assets/error.json deleted file mode 100644 index 94d600d..0000000 --- a/assets/error.json +++ /dev/null @@ -1 +0,0 @@ -"%s" diff --git a/assets/form.html b/assets/form.html new file mode 100644 index 0000000..8bc0f17 --- /dev/null +++ b/assets/form.html @@ -0,0 +1,20 @@ + + + + + + +bunkergate.org + + + + +%s + + + + + \ No newline at end of file diff --git a/assets/form_begin.html b/assets/form_begin.html new file mode 100644 index 0000000..4da1ce9 --- /dev/null +++ b/assets/form_begin.html @@ -0,0 +1,11 @@ + + + + + + +bunkergate.org + + + + diff --git a/assets/form_end.html b/assets/form_end.html new file mode 100644 index 0000000..6131a40 --- /dev/null +++ b/assets/form_end.html @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/assets/static/css/retro.css b/assets/static/css/retro.css new file mode 100644 index 0000000..7467a37 --- /dev/null +++ b/assets/static/css/retro.css @@ -0,0 +1,200 @@ +pre, +code { + font-family: Menlo, Monaco, "Courier New", monospace; +} + +pre { + padding: .5rem; + line-height: 1.25; + overflow-x: scroll; +} + +@media print { + *, + *:before, + *:after { + background: transparent !important; + color: #000 !important; + box-shadow: none !important; + text-shadow: none !important; + } + + a, + a:visited { + text-decoration: underline; + } + + a[href]:after { + content: " (" attr(href) ")"; + } + + abbr[title]:after { + content: " (" attr(title) ")"; + } + + a[href^="#"]:after, + a[href^="javascript:"]:after { + content: ""; + } + + pre, + blockquote { + border: 1px solid #999; + page-break-inside: avoid; + } + + thead { + display: table-header-group; + } + + tr, + img { + page-break-inside: avoid; + } + + img { + max-width: 100% !important; + } + + p, + h2, + h3 { + orphans: 3; + widows: 3; + } + + h2, + h3 { + page-break-after: avoid; + } +} + +a, +a:visited { + color: #01ff70; +} + +a:hover, +a:focus, +a:active { + color: #2ecc40; +} + +.retro-no-decoration { + text-decoration: none; +} + +html { + font-size: 12px; +} + +@media screen and (min-width: 32rem) and (max-width: 48rem) { + html { + font-size: 15px; + } +} + +@media screen and (min-width: 48rem) { + html { + font-size: 16px; + } +} + +body { + line-height: 1.85; +} + +p, +.retro-p { + font-size: 1rem; + margin-bottom: 1.3rem; +} + +h1, +.retro-h1, +h2, +.retro-h2, +h3, +.retro-h3, +h4, +.retro-h4 { + margin: 1.414rem 0 .5rem; + font-weight: inherit; + line-height: 1.42; +} + +h1, +.retro-h1 { + margin-top: 0; + font-size: 3.998rem; +} + +h2, +.retro-h2 { + font-size: 2.827rem; +} + +h3, +.retro-h3 { + font-size: 1.999rem; +} + +h4, +.retro-h4 { + font-size: 1.414rem; +} + +h5, +.retro-h5 { + font-size: 1.121rem; +} + +h6, +.retro-h6 { + font-size: .88rem; +} + +small, +.retro-small { + font-size: .707em; +} + +/* https://github.com/mrmrs/fluidity */ + +img, +canvas, +iframe, +video, +svg, +select, +textarea { + max-width: 100%; +} + +html, +body { + background-color: #222; + min-height: 100%; +} + +html { + font-size: 18px; +} + +body { + color: #fafafa; + font-family: "Courier New"; + line-height: 1.45; + margin: 6rem auto 1rem; + max-width: 48rem; + padding: .25rem; +} + +pre { + background-color: #333; +} + +blockquote { + border-left: 3px solid #01ff70; + padding-left: 1rem; +} \ No newline at end of file diff --git a/conf/clog.conf b/conf/clog.conf index 3476b52..c45e48d 100644 --- a/conf/clog.conf +++ b/conf/clog.conf @@ -57,12 +57,12 @@ domain * { } # toy endpoint - route ^/form { + route /form { handler get_entry_form methods get } - route ^/form { + route /form { handler post_entry_form methods post diff --git a/src/clog.c b/src/clog.c index 87129e5..80906d3 100644 --- a/src/clog.c +++ b/src/clog.c @@ -240,17 +240,29 @@ int post_entry_form(struct http_request *req) { // continue; // } + http_response_header(req, "content-type", "text/html; charset=utf-8"); + + kore_buf_append(resp_buf, asset_form_begin_html, asset_len_form_begin_html); + // Append rendered MD entry. - kore_buf_appendf( + size_t len = 0; + char *str = NULL; + str = kore_buf_stringify(html_buf, &len); + kore_buf_append( resp_buf, - (const char *) asset_entry_html, - id, - title, - "1981-12-23 06:02:00", - kore_buf_stringify(html_buf, NULL) + str, + len + ); + + kore_buf_append(resp_buf, asset_form_end_html, asset_len_form_end_html); + + http_response( + req, + HTTP_STATUS_OK, + resp_buf->data, + resp_buf->offset ); - http_ok_resp(req, HTTP_STATUS_OK, resp_buf); kore_buf_free(html_buf); kore_buf_free(resp_buf); @@ -692,7 +704,10 @@ static int render_md(const char *in, struct kore_buf *out) { int err = 0; static unsigned parser_flags = 0; - static unsigned renderer_flags = MD_HTML_FLAG_DEBUG; + static unsigned renderer_flags = 0; + + parser_flags |= MD_FLAG_TABLES; + // render_flags |= MD_HTML_FLAG_DEBUG; err = md_html( in, -- cgit v1.2.3