commit 8a356e33786720d34eeae60e39b70ec397bf0852
parent ddb31bfdd167f5874351ed3fe942a47a931824da
Author: Henry Unite <unitehenry@gmail.com>
Date: Thu, 9 Apr 2026 04:28:09 +0000
feat: path root
Diffstat:
7 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
@@ -12,3 +12,7 @@ blog/
└── static/
└── css/style.css
```
+
+**TODO**
+
+- Specify `build` path
diff --git a/build/blog/first-post.html b/build/blog/first-post.html
@@ -1,2 +0,0 @@
-<h1 id="first-post">First Post</h1>
-<p>This is my first blog post.</p>
diff --git a/build/blog/nested/nested-1.html b/build/blog/nested/nested-1.html
@@ -1 +0,0 @@
-<p>nested content</p>
diff --git a/build/index.html b/build/index.html
@@ -1,2 +0,0 @@
-<h2 id="welcome-to-my-site">Welcome to my Site</h2>
-<p>This is my website.</p>
diff --git a/src/main.c b/src/main.c
@@ -1,4 +1,5 @@
#include "create_subdirectories.h"
+#include "path_root.h"
#include "string_list.h"
#include "string_replace.h"
#include <dirent.h>
@@ -66,7 +67,15 @@ void to_write_path(char **write_path, char *read_path) {
*write_path = str_replace(replace_path, ".md", ".html");
- *write_path = str_replace(*write_path, "content/", "build/");
+ char *root;
+
+ path_root(&root, *write_path);
+
+ char root_t[strlen(root) + strlen("/")];
+
+ snprintf(root_t, strlen(root) + 2, "%s/", root);
+
+ *write_path = str_replace(*write_path, root_t, "build/");
}
void generate_pages(StringList *list) {
diff --git a/src/path_root.c b/src/path_root.c
@@ -0,0 +1,15 @@
+#include "path_root.h"
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
+
+void path_root(char **root, char* path) {
+ char *path_copy = strdup(path);
+ if (!path_copy) {
+ *root = NULL;
+ return;
+ }
+ char *dir = dirname(path_copy);
+ *root = strdup(dir);
+ free(path_copy);
+}
+\ No newline at end of file
diff --git a/src/path_root.h b/src/path_root.h
@@ -0,0 +1 @@
+void path_root(char **root, char* path);
+\ No newline at end of file