2026-03-01 22:43:41 +09:00
|
|
|
#include <taiga.h>
|
|
|
|
|
|
2026-03-02 07:14:39 +09:00
|
|
|
xemil_t* skinconf;
|
|
|
|
|
|
2026-03-02 17:32:20 +09:00
|
|
|
static int scan(const char* top, const char* path) {
|
|
|
|
|
char* in = u_strvacat("site/content/", path, NULL);
|
|
|
|
|
char* out = u_strvacat("build/", path, NULL);
|
2026-03-01 23:36:33 +09:00
|
|
|
IO_DIR* dir;
|
2026-03-02 17:32:20 +09:00
|
|
|
|
2026-03-02 01:08:36 +09:00
|
|
|
io_mkdir(out, 0755);
|
2026-03-02 17:32:20 +09:00
|
|
|
if((dir = io_opendir(in)) != NULL) {
|
2026-03-01 23:36:33 +09:00
|
|
|
struct io_dirent* d;
|
|
|
|
|
|
2026-03-02 17:32:20 +09:00
|
|
|
while((d = io_readdir(dir)) != NULL) {
|
|
|
|
|
char* p;
|
2026-03-01 23:36:33 +09:00
|
|
|
struct io_stat s;
|
|
|
|
|
|
|
|
|
|
if(strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) continue;
|
|
|
|
|
|
2026-03-02 01:08:36 +09:00
|
|
|
p = u_strvacat(in, d->d_name, NULL);
|
2026-03-02 17:32:20 +09:00
|
|
|
if(io_stat(p, &s) == 0) {
|
|
|
|
|
if(IO_S_ISDIR(s.st_mode)) {
|
2026-03-02 01:08:36 +09:00
|
|
|
char* p2 = u_strvacat(d->d_name, "/", NULL);
|
2026-03-02 17:32:20 +09:00
|
|
|
char* t = u_strvacat(top, "../", NULL);
|
|
|
|
|
if(!scan(t, p2)) {
|
2026-03-02 07:14:39 +09:00
|
|
|
free(t);
|
|
|
|
|
free(p2);
|
|
|
|
|
free(p);
|
|
|
|
|
io_closedir(dir);
|
|
|
|
|
free(out);
|
|
|
|
|
free(in);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
free(t);
|
2026-03-02 01:08:36 +09:00
|
|
|
free(p2);
|
2026-03-02 17:32:20 +09:00
|
|
|
} else if(strcmp(d->d_name, "index.xml") == 0) {
|
2026-03-02 07:14:39 +09:00
|
|
|
printf("%s:\n", p);
|
2026-03-02 17:32:20 +09:00
|
|
|
if(!process(top, out, p)) {
|
2026-03-02 07:14:39 +09:00
|
|
|
free(p);
|
|
|
|
|
io_closedir(dir);
|
|
|
|
|
free(out);
|
|
|
|
|
free(in);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2026-03-01 23:36:33 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
io_closedir(dir);
|
|
|
|
|
}
|
2026-03-02 17:32:20 +09:00
|
|
|
|
2026-03-01 23:36:33 +09:00
|
|
|
free(out);
|
|
|
|
|
free(in);
|
2026-03-02 07:14:39 +09:00
|
|
|
|
|
|
|
|
return 1;
|
2026-03-01 23:36:33 +09:00
|
|
|
}
|
|
|
|
|
|
2026-03-02 17:32:20 +09:00
|
|
|
int action_site(int argc, char** argv) {
|
|
|
|
|
int st = 0;
|
2026-03-02 07:14:39 +09:00
|
|
|
FILE* css;
|
|
|
|
|
|
2026-03-01 23:36:33 +09:00
|
|
|
io_mkdir("build", 0755);
|
|
|
|
|
|
2026-03-02 17:32:20 +09:00
|
|
|
if((skinconf = xl_open_file("site/skinconf.xml")) == NULL || !xl_parse(skinconf)) {
|
2026-03-02 07:14:39 +09:00
|
|
|
fprintf(stderr, "Failed to parse site/skinconf.xml!\n");
|
|
|
|
|
st = 1;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 17:32:20 +09:00
|
|
|
if((css = fopen("build/style.css", "w")) == NULL) {
|
2026-03-02 07:14:39 +09:00
|
|
|
st = 1;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
2026-03-02 17:32:20 +09:00
|
|
|
classic_stylesheet(css, "build/");
|
2026-03-02 07:14:39 +09:00
|
|
|
fclose(css);
|
|
|
|
|
|
2026-03-02 17:32:20 +09:00
|
|
|
if(!scan("", "")) {
|
2026-03-02 07:14:39 +09:00
|
|
|
st = 1;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cleanup:;
|
|
|
|
|
if(skinconf != NULL) xl_close(skinconf);
|
|
|
|
|
|
2026-03-02 17:32:20 +09:00
|
|
|
if(st == 0) {
|
2026-03-02 07:14:39 +09:00
|
|
|
fprintf(stderr, "\nBuild successful\n");
|
2026-03-02 17:32:20 +09:00
|
|
|
} else {
|
2026-03-02 07:14:39 +09:00
|
|
|
fprintf(stderr, "\nBuild failed!\n");
|
|
|
|
|
}
|
2026-03-01 23:36:33 +09:00
|
|
|
|
2026-03-01 22:43:41 +09:00
|
|
|
return 0;
|
|
|
|
|
}
|