This commit is contained in:
parent
adaa379cfa
commit
38ed0f4910
11 changed files with 130 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
104
src/action/markdown_dir.c
Normal 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;
|
||||
}
|
||||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
2
src/stb_ds.c
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define STB_DS_IMPLEMENTATION
|
||||
#include <taiga.h>
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue