wip markdown-dir
All checks were successful
pyrite-dev/taiga/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-03-10 03:59:18 +09:00
commit 38ed0f4910
Signed by: nishi
GPG key ID: 27EF69B208EB9343
11 changed files with 130 additions and 6 deletions

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "external/md4c"]
path = external/md4c
url = https://github.com/mity/md4c
[submodule "external/stb"]
path = external/stb
url = https://github.com/nothings/stb

View file

@ -1,5 +1,5 @@
CC ?= cc
CFLAGS ?= -I external/xemil/include -I external/md4c/src -I src $(DEFS)
CFLAGS ?= -I external/xemil/include -I external/md4c/src -I external/stb -I src $(DEFS)
LDFLAGS ?=
LIBS ?=
AFTER ?=

1
external/stb vendored Submodule

@ -0,0 +1 @@
Subproject commit 2fb8c5a3deb2110c89669f8d6f36e5833b556b44

View file

@ -29,6 +29,9 @@ src/src_action_help.o: src/action/help.c
OBJS += src/src_action_markdown.o
src/src_action_markdown.o: src/action/markdown.c
$(CC) $(CFLAGS) -c -o $@ src/action/markdown.c
OBJS += src/src_action_markdown_dir.o
src/src_action_markdown_dir.o: src/action/markdown_dir.c
$(CC) $(CFLAGS) -c -o $@ src/action/markdown_dir.c
OBJS += src/src_action_seed.o
src/src_action_seed.o: src/action/seed.c
$(CC) $(CFLAGS) -c -o $@ src/action/seed.c
@ -80,6 +83,9 @@ src/src_skin_classic.o: src/skin/classic.c
OBJS += src/src_skin_simple.o
src/src_skin_simple.o: src/skin/simple.c
$(CC) $(CFLAGS) -c -o $@ src/skin/simple.c
OBJS += src/src_stb_ds.o
src/src_stb_ds.o: src/stb_ds.c
$(CC) $(CFLAGS) -c -o $@ src/stb_ds.c
OBJS += src/src_util.o
src/src_util.o: src/util.c
$(CC) $(CFLAGS) -c -o $@ src/util.c

View file

@ -2,9 +2,10 @@
int action_help(int argc, char** argv) {
printf("Actions:\n");
printf(" help Show this help\n");
printf(" seed Creates a new website\n");
printf(" site Builds an website (default action)\n");
printf(" markdown Converts Markdown document to Taiga document\n");
printf(" help Show this help\n");
printf(" seed Creates a new website\n");
printf(" site Builds an website (default action)\n");
printf(" markdown Converts Markdown document to Taiga document\n");
printf(" markdown-dir Converts Markdown document directory to Taiga document directory\n");
return 0;
}

View file

@ -454,6 +454,7 @@ int action_markdown(int argc, char** argv) {
indent--;
if(title != NULL) free(title);
title = NULL;
free(buffer);

104
src/action/markdown_dir.c Normal file
View file

@ -0,0 +1,104 @@
#include <taiga.h>
static int scan(const char* inp, const char* path) {
char* in = u_strvacat(inp, "/", path, NULL);
char* out = u_strvacat("site/content/", path, NULL);
IO_DIR* dir;
io_mkdir(out, 0755);
if((dir = io_opendir(in)) != NULL) {
struct io_dirent* d;
while((d = io_readdir(dir)) != NULL) {
char* p;
struct io_stat s;
if(strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) continue;
p = u_strvacat(in, d->d_name, NULL);
if(io_stat(p, &s) == 0) {
char* str;
int is_md = 0;
str = strrchr(d->d_name, '.');
if(str != NULL && strcmp(str, ".md") == 0) is_md = 1;
if(IO_S_ISDIR(s.st_mode)) {
char* p2 = u_strvacat(d->d_name, "/", NULL);
char* o = u_strvacat(out, d->d_name, NULL);
io_mkdir(o, 0755);
free(o);
if(!scan(inp, p2)) {
free(p2);
free(p);
io_closedir(dir);
free(out);
free(in);
return 0;
}
free(p2);
} else if(is_md) {
char** argv = NULL;
char* o = NULL;
printf("%s:\n", p);
arrput(argv, p);
if(strcmp(d->d_name, "README.md") == 0) {
o = u_strvacat(out, "index.xml", NULL);
} else {
char* n = u_strdup(d->d_name);
char* str;
char* d;
if((str = strchr(n, '.')) != NULL) str[0] = 0;
d = u_strvacat(out, n, NULL);
o = u_strvacat(d, "/index.xml", NULL);
io_mkdir(d, 0755);
free(d);
free(n);
}
if(o != NULL) arrput(argv, o);
if(action_markdown(arrlen(argv), argv)) {
free(o);
arrfree(argv);
free(p);
io_closedir(dir);
free(out);
free(in);
return 0;
}
free(o);
arrfree(argv);
}
}
free(p);
}
io_closedir(dir);
}
free(out);
free(in);
return 1;
}
int action_markdown_dir(int argc, char** argv) {
if(argc != 1) {
fprintf(stderr, "Usage: markdown-dir input\n");
return 1;
}
if(!scan(argv[0], "")) {
return 1;
}
return 0;
}

View file

@ -32,6 +32,8 @@ int main(int argc, char** argv) {
return action_seed(target_argc, target_argv);
} else if(strcmp(action, "markdown") == 0) {
return action_markdown(target_argc, target_argv);
} else if(strcmp(action, "markdown-dir") == 0) {
return action_markdown_dir(target_argc, target_argv);
}
fprintf(stderr, "Unknown action\n");

View file

@ -232,7 +232,7 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body
text = u_path(top, text);
fprintf(out, " <a href=\"%s\"><img src=\"%s\" alt=\"%s\" border=\"0\"%s></a>\n", link, text, name, size);
fprintf(out, " <img src=\"%simage/fill.gif\" width=\"96\" alt=\"filling\">\n", top);
fprintf(out, " <img src=\"%simage/fill.gif\" width=\"96\" height=\"1\" alt=\"filling\">\n", top);
free(text);
}

2
src/stb_ds.c Normal file
View file

@ -0,0 +1,2 @@
#define STB_DS_IMPLEMENTATION
#include <taiga.h>

View file

@ -18,6 +18,7 @@
#include <xemil.h>
#include <md4c.h>
#include <stb_ds.h>
#ifdef _WIN32
#define io_mkdir(x, y) _mkdir(x)
@ -65,6 +66,9 @@ int action_seed(int argc, char** argv);
/* action/markdown.c */
int action_markdown(int argc, char** argv);
/* action/markdown_dir.c */
int action_markdown_dir(int argc, char** argv);
/* util.c */
char* u_strvacat(const char* str, ...);
char* u_strdup(const char* str);