Mercurial
diff mrjunejune/main.c @ 169:295ac2e5ec00
[MrJuneJune] Created separate target for generating html from md.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 19 Jan 2026 17:33:18 -0800 |
| parents | f3084bca7317 |
| children | 90dfcef375fb |
line wrap: on
line diff
--- a/mrjunejune/main.c Mon Jan 19 16:29:02 2026 -0800 +++ b/mrjunejune/main.c Mon Jan 19 17:33:18 2026 -0800 @@ -1,4 +1,3 @@ -// Debug mode is now controlled by build target: use //seobeo:seobeo_tcp_server_ws_debug #include "seobeo/seobeo.h" #include "markdown_converter/markdown_to_html.h" #include <time.h> @@ -6,25 +5,6 @@ // UUID + /tmp/ + format (max 4) #define TMP_FILE_LENGTH 47 #define UUID_LEN 37 -#define BLOG_HTML "<!DOCTYPE html>" \ -"<html lang=\"en\">" \ -"<head>" \ -" <meta charset=\"UTF-8\">" \ -" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" \ -" <title>Multi Threading in JS</title>" \ -" {{/parts/base_head.html}}" \ -" <link rel=\"stylesheet\" href=\"/public/highlight/a11y-dark.min.css\" media=\"(prefers-color-scheme: dark)\">" \ -" <link rel=\"stylesheet\" href=\"/public/highlight/a11y-light.min.css\" media=\"(prefers-color-scheme: light)\">" \ -" <script src=\"/public/highlight/highlight.min.js\"></script>" \ -"</head>" \ -"<body>" \ -" {{/parts/header.html}}" \ -" <main>" \ -"%s" \ -" </main>" \ -" {{/parts/footer.html}}" \ -" <script>hljs.highlightAll();</script>"\ -"</body>" volatile sig_atomic_t stop_server = 0; static _Atomic uint32_t counter = 0; @@ -457,7 +437,6 @@ printf("DEBUG: Served and deleted file: %s (%zu bytes)\n", filename, file_size); - // Set proper Content-Length for binary data char *content_length = Dowa_Arena_Allocate(arena, 32); snprintf(content_length, 32, "%zu", file_size); @@ -481,33 +460,15 @@ Seobeo_Request_Entry *RenderBlog(Seobeo_Request_Entry *req, Dowa_Arena *arena) { - Seobeo_Log(SEOBEO_DEBUG, "[CURR], Blog\n"); Seobeo_Request_Entry *resp = NULL; + char *file_path = Dowa_Arena_Allocate(arena, 1024); void *blog_id_kv = Dowa_HashMap_Get_Ptr(req, ":blog_id"); - if (!blog_id_kv) - { - char *error_msg = "No Blog Id"; - Dowa_HashMap_Push_Arena(resp, "status", "404", arena); - Dowa_HashMap_Push_Arena(resp, "content-type", "text/plain", arena); - Dowa_HashMap_Push_Arena(resp, "body", error_msg, arena); - return resp; - } + char *blog_id = ((Seobeo_Request_Entry*)blog_id_kv)->value; + snprintf(file_path, 1024, "/blog/%s/index.html", blog_id); - const char *blog_id = ((Seobeo_Request_Entry *)blog_id_kv)->value; - char *md_path = Dowa_Arena_Allocate(arena, 512); - sprintf(md_path, "/blog/%s/index.md", blog_id); - - size_t md_file_size = 0; - char *md_file = Seobeo_Web_LoadFile(md_path, &md_file_size); - - char *md = markdown_to_html(md_file); - size_t buffer_sizes = 100 * 1024; // TODO: Think about the sizes - char *ssr_body = Dowa_Arena_Allocate(arena, buffer_sizes); - char *final_body = Dowa_Arena_Allocate(arena, buffer_sizes); - - snprintf(ssr_body, 100*1024, BLOG_HTML, md); - Seobeo_Render_Html(final_body, ssr_body, arena); + char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024); + Seobeo_Render_Html_FilePath(final_body, file_path, arena); Dowa_HashMap_Push_Arena(resp, "body", final_body, arena); return resp; }