diff mrjunejune/main.c @ 78:e7bf9e002850

amend
author June Park <parkjune1995@gmail.com>
date Wed, 31 Dec 2025 15:07:43 -0800
parents c348ac875294
children 5710108c949e
line wrap: on
line diff
--- a/mrjunejune/main.c	Wed Dec 31 14:17:40 2025 -0800
+++ b/mrjunejune/main.c	Wed Dec 31 15:07:43 2025 -0800
@@ -8,20 +8,88 @@
   stop_server = 1;
 }
 
+void Seobeo_ServerSideRender(
+    char *final_body,
+    char *path,
+    Dowa_Arena *arena
+) {
+  size_t html_size = 0;
+  char *template = Seobeo_Web_LoadFile(path, &html_size);
+  if (!template) return;
+
+  size_t current_offset = 0;
+  char *cursor = template;
+
+  int32 token_len = 2;
+
+  while (true)
+  {
+    char *start_tag = strstr(cursor, "{{");
+    if (!start_tag) break;
+
+    char *end_tag = strstr(start_tag, "}}");
+    if (!end_tag) break;
+
+    size_t leading_len = start_tag - cursor;
+    memcpy(final_body + current_offset, cursor, leading_len);
+    current_offset += leading_len;
+
+    size_t name_len = end_tag - (start_tag + token_len);
+    char *include_name = Dowa_Arena_Allocate(arena, name_len + 1);
+    memcpy(include_name, start_tag + token_len, name_len);
+    include_name[name_len] = '\0';
+
+    size_t sub_file_size = 0;
+    char *sub_content = Seobeo_Web_LoadFile(include_name, &sub_file_size);
+    if (sub_content)
+    {
+      memcpy(final_body + current_offset, sub_content, sub_file_size);
+      current_offset += sub_file_size;
+      free(sub_content);
+    }
+
+    cursor = end_tag + 2;
+  }
+  strcpy(final_body + current_offset, cursor);
+  free(template);
+}
+
 Seobeo_Request_Entry* GetHomePage(Seobeo_Request_Entry *req, Dowa_Arena *arena)
 {
-  Seobeo_Request_Entry *resp = NULL;
-  char *body = Dowa_Arena_Allocate(arena, 10 * 1024);
-  size_t body_size = 0; 
-  char *file_content = Seobeo_Web_LoadFile("/index.html", &body_size);
-  snprintf(body, 10 * 1024, file_content);
-  free(file_content);
+  Seobeo_Request_Entry *resp = NULL; 
+  char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024); // 50KB buffer
+  Seobeo_ServerSideRender(final_body, "/index.html", arena);
+  Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
+  return resp;
+}
 
-  Dowa_HashMap_Push_Arena(resp, "body", body, arena);
+Seobeo_Request_Entry* GetResume(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, "/resume/index.html", arena);
+  Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
+  return resp;
+}
+
+Seobeo_Request_Entry* GetTools(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, "/tools/index.html", arena);
+  Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
   return resp;
 }
 
 
+Seobeo_Request_Entry* GetMDToHTML(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, "/tools/markdown_to_html/index.html", arena);
+  Dowa_HashMap_Push_Arena(resp, "body", final_body, arena);
+  return resp;
+}
 
 Seobeo_Request_Entry* GetUser(Seobeo_Request_Entry *req, Dowa_Arena *arena)
 {
@@ -36,10 +104,20 @@
   return resp;
 }
 
-
 int main(void)
 {
   Seobeo_Router_Init();
   Seobeo_Router_Register("GET", "/", GetHomePage);
+  Seobeo_Router_Register("GET", "/index.html", GetHomePage);
+
+  Seobeo_Router_Register("GET", "/resume", GetResume);
+  Seobeo_Router_Register("GET", "/resume/index.html", GetResume);
+
+  Seobeo_Router_Register("GET", "/tools", GetTools);
+  Seobeo_Router_Register("GET", "/tools/index.html", GetTools);
+
+  Seobeo_Router_Register("GET", "/tools/markdown_to_html", GetMDToHTML);
+  Seobeo_Router_Register("GET", "/tools/markdown_to_html/index.html", GetMDToHTML);
+
   Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2);
 }