commit 840d6e61a644d755e87c972c917112faf051e150
parent 416e409d6c905d6179fe0bf0b1af07611db0e5e5
Author: Henry Unite <unitehenry@gmail.com>
Date: Thu, 9 Apr 2026 03:42:13 +0000
feat: write path
Diffstat:
3 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/src/main.c b/src/main.c
@@ -1,4 +1,5 @@
#include "string_list.h"
+#include "string_replace.h"
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
@@ -61,6 +62,24 @@ void generate_pages(StringList *list) {
int i = 0;
while (list->strings[i] != NULL) {
+ char replace_path[strlen(list->strings[i])];
+
+ strcpy(replace_path, list->strings[i]);
+
+ char *write_path;
+
+ write_path = str_replace(replace_path, ".md", ".html");
+
+ write_path = str_replace(write_path, "content/", "static/");
+
+ printf("filepath: %s\n", write_path);
+
+ // open file to write
+
+ i++;
+
+ continue;
+
FILE *fp = run_pandoc(list->strings[i]);
char *line = NULL;
@@ -70,7 +89,7 @@ void generate_pages(StringList *list) {
ssize_t read;
while ((read = getline(&line, &len, fp)) != -1) {
- printf("%s", line);
+ // printf("%s", line);
}
fclose(fp);
diff --git a/src/string_replace.c b/src/string_replace.c
@@ -0,0 +1,57 @@
+#include "string_replace.h"
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *str_replace(const char *str, const char *old_sub, const char *new_sub) {
+ size_t old_len = strlen(old_sub);
+
+ if (old_len == 0) {
+ return strdup(str);
+ }
+
+ size_t new_len = strlen(new_sub);
+
+ size_t str_len = strlen(str);
+
+ size_t count = 0;
+
+ const char *p = str;
+
+ while ((p = strstr(p, old_sub)) != NULL) {
+ count++;
+ p += old_len;
+ }
+
+ if (count == 0) {
+ return strdup(str);
+ }
+
+ size_t new_str_len = str_len + count * (new_len - old_len) + 1;
+
+ char *result = malloc(new_str_len);
+
+ if (!result) {
+ return NULL;
+ }
+
+ char *dest = result;
+
+ const char *src = str;
+
+ while (*src) {
+ if (strstr(src, old_sub) == src) {
+ strcpy(dest, new_sub);
+
+ dest += new_len;
+
+ src += old_len;
+ } else {
+ *dest++ = *src++;
+ }
+ }
+
+ *dest = '\0';
+
+ return result;
+}
diff --git a/src/string_replace.h b/src/string_replace.h
@@ -0,0 +1,3 @@
+#include <stddef.h>
+
+char *str_replace(const char *str, const char *old_sub, const char *new_sub);
+\ No newline at end of file