diff mrjunejune/main.c @ 158:1c0878eb17de

[MrJuneJune] Readme file gets compiled in server side.
author June Park <parkjune1995@gmail.com>
date Wed, 14 Jan 2026 07:59:19 -0800
parents 7a63e41a21fb
children f3084bca7317
line wrap: on
line diff
--- a/mrjunejune/main.c	Tue Jan 13 19:18:47 2026 -0800
+++ b/mrjunejune/main.c	Wed Jan 14 07:59:19 2026 -0800
@@ -1,10 +1,30 @@
 // 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>
 
 // 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;
@@ -15,17 +35,12 @@
   stop_server = 1;
 }
 
-void Seobeo_ServerSideRender(
+void Seobeo_Render_Html(
     char *final_body,
-    char *path,
+    char *template,
     Dowa_Arena *arena
-) {
-  Seobeo_Log(SEOBEO_DEBUG, "[Curr] %s\n", path);
-  size_t html_size = 0;
-  char *template = Seobeo_Web_LoadFile(path, &html_size);
-  if (!template) return;
-  Seobeo_Log(SEOBEO_DEBUG, "[Curr] ??\n");
-
+)
+{
   size_t current_offset = 0;
   char *cursor = template;
 
@@ -61,14 +76,26 @@
     cursor = end_tag + 2;
   }
   strcpy(final_body + current_offset, cursor);
-  free(template);
+}
+
+
+void Seobeo_Render_Html_FilePath(
+    char *final_body,
+    char *path,
+    Dowa_Arena *arena
+) {
+  Seobeo_Log(SEOBEO_DEBUG, "[Curr] %s\n", path);
+  size_t html_size = 0;
+  char *template = Seobeo_Web_LoadFile(path, &html_size);
+  if (!template) return;
+  Seobeo_Render_Html(final_body, template, arena);
 }
 
 Seobeo_Request_Entry* GetHomePage(Seobeo_Request_Entry *req, Dowa_Arena *arena)
 {
   Seobeo_Request_Entry *resp = NULL; 
   char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024);
-  Seobeo_ServerSideRender(final_body, "/index.html", arena);
+  Seobeo_Render_Html_FilePath(final_body, "/index.html", arena);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -77,7 +104,7 @@
 {
   Seobeo_Request_Entry *resp = NULL; 
   char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024);
-  Seobeo_ServerSideRender(final_body, "/resume/index.html", arena);
+  Seobeo_Render_Html_FilePath(final_body, "/resume/index.html", arena);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -86,7 +113,7 @@
 {
   Seobeo_Request_Entry *resp = NULL; 
   char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024);
-  Seobeo_ServerSideRender(final_body, "/tools/index.html", arena);
+  Seobeo_Render_Html_FilePath(final_body, "/tools/index.html", arena);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -96,7 +123,7 @@
 {
   Seobeo_Request_Entry *resp = NULL;
   char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024);
-  Seobeo_ServerSideRender(final_body, "/tools/markdown_to_html/index.html", arena);
+  Seobeo_Render_Html_FilePath(final_body, "/tools/markdown_to_html/index.html", arena);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -105,7 +132,7 @@
 {
   Seobeo_Request_Entry *resp = NULL;
   char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024);
-  Seobeo_ServerSideRender(final_body, "/tools/file_converter/index.html", arena);
+  Seobeo_Render_Html_FilePath(final_body, "/tools/file_converter/index.html", arena);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -443,7 +470,7 @@
 {
   Seobeo_Request_Entry *resp = NULL;
   char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024);
-  Seobeo_ServerSideRender(final_body, "/blog/index.html", arena);
+  Seobeo_Render_Html_FilePath(final_body, "/blog/index.html", arena);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -451,7 +478,7 @@
 
 Seobeo_Request_Entry *RenderBlog(Seobeo_Request_Entry *req, Dowa_Arena *arena)
 {
-  Seobeo_Log(SEOBEO_DEBUG, "[CURR], Hello\n");
+  Seobeo_Log(SEOBEO_DEBUG, "[CURR], Blog\n");
   Seobeo_Request_Entry *resp = NULL;
 
   void *blog_id_kv = Dowa_HashMap_Get_Ptr(req, ":blog_id");
@@ -465,11 +492,19 @@
   }
 
   const char *blog_id = ((Seobeo_Request_Entry *)blog_id_kv)->value;
-  char *html_path = Dowa_Arena_Allocate(arena, 512);
-  sprintf(html_path, "/blog/%s/index.html", blog_id);
+  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 *final_body = Dowa_Arena_Allocate(arena, 100 * 1024); // TODO: Think about the sizes
-  Seobeo_ServerSideRender(final_body, html_path, arena);
+  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);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -492,7 +527,7 @@
 {
   Seobeo_Request_Entry *resp = NULL;
   char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024);
-  Seobeo_ServerSideRender(final_body, "/talk/index.html", arena);
+  Seobeo_Render_Html_FilePath(final_body, "/talk/index.html", arena);
   Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
@@ -534,11 +569,8 @@
 
   // -- Talk --/
   Seobeo_Router_Register("GET", "/talk", GetTalk);
-  // TODO: Bug where I can't est redriect huh...
   Seobeo_Router_Register("GET", "/talk/index.html", GetRedirectTalk);
 
-  printf("Registered Websockets\n");
-
   Seobeo_WebSocket_Server_Init();
   Seobeo_WebSocket_Server_Register("/chat", Chat_Handler, NULL);