This commit is contained in:
parent
05cce3405e
commit
f4cccab2d1
6 changed files with 168 additions and 18 deletions
2
external/xemil
vendored
2
external/xemil
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit e5b592e29a3be4b021836dd364f94c8e4137ef4e
|
||||
Subproject commit e8f00f411100f7e2cc66d935204cd7e1d058ad71
|
||||
3
objs.mk
3
objs.mk
|
|
@ -14,6 +14,9 @@ src/external_xemil_src_unicode.o: external/xemil/src/unicode.c
|
|||
OBJS += src/external_xemil_src_util.o
|
||||
src/external_xemil_src_util.o: external/xemil/src/util.c
|
||||
$(CC) $(CFLAGS) -c -o $@ external/xemil/src/util.c
|
||||
OBJS += src/src_classic.o
|
||||
src/src_classic.o: src/classic.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/classic.c
|
||||
OBJS += src/src_help.o
|
||||
src/src_help.o: src/help.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/help.c
|
||||
|
|
|
|||
|
|
@ -1,16 +1,98 @@
|
|||
#include <taiga.h>
|
||||
|
||||
void process(const char* out, const char* full){
|
||||
char* f = strrchr(full, '/');
|
||||
static FILE* f;
|
||||
|
||||
if(f != NULL) f = f + 1;
|
||||
static int parse_file(const char* top, const char* full){
|
||||
xemil_t* handle = xl_open_file(full);
|
||||
int st = 1;
|
||||
|
||||
if(f != NULL){
|
||||
char* n;
|
||||
handle->new_text = 1;
|
||||
|
||||
f = u_strdup(f);
|
||||
if((n = strrchr(f, '.')) != NULL) n[0] = 0;
|
||||
if(handle != NULL && xl_parse(handle)){
|
||||
if(handle->root == NULL || strcmp(handle->root->name, "document") != 0){
|
||||
fprintf(stderr, "Root element has to be document\n");
|
||||
st = 0;
|
||||
}
|
||||
|
||||
free(f);
|
||||
if(st){
|
||||
char* title = NULL;
|
||||
xl_node_t* node = NULL;
|
||||
xl_node_t* header = NULL;
|
||||
xl_node_t* body = NULL;
|
||||
|
||||
if(handle->root != NULL) node = handle->root->first_child;
|
||||
while(node != NULL){
|
||||
if(node->type == XL_NODE_NODE && strcmp(node->name, "header") == 0){
|
||||
xl_node_t* n = node->first_child;
|
||||
|
||||
while(n != NULL){
|
||||
if(n->type == XL_NODE_NODE && strcmp(n->name, "title") == 0){
|
||||
if(title != NULL) free(title);
|
||||
title = u_strdup(n->text);
|
||||
}
|
||||
n = n->next;
|
||||
}
|
||||
|
||||
header = node;
|
||||
}else if(node->type == XL_NODE_NODE && strcmp(node->name, "body") == 0){
|
||||
body = node;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
if(title == NULL) title = u_strdup("Untitled");
|
||||
|
||||
fprintf(f, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
|
||||
fprintf(f, "<html>\n");
|
||||
fprintf(f, " <head>\n");
|
||||
fprintf(f, " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n");
|
||||
fprintf(f, " <title>%s</title>\n", title);
|
||||
classic_head(f, top, header);
|
||||
fprintf(f, " </head>\n");
|
||||
fprintf(f, " <body>\n");
|
||||
classic_body(f, top, title, body);
|
||||
fprintf(f, " </body>\n");
|
||||
fprintf(f, "</html>\n");
|
||||
|
||||
free(title);
|
||||
}
|
||||
}else{
|
||||
fprintf(stderr, "Parse failed!\n", full);
|
||||
st = 0;
|
||||
}
|
||||
|
||||
if(handle != NULL) xl_close(handle);
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
int process(const char* top, const char* out, const char* full){
|
||||
char* fn = strrchr(full, '/');
|
||||
|
||||
if(fn != NULL) fn = fn + 1;
|
||||
|
||||
if(fn != NULL){
|
||||
char* n;
|
||||
char* p;
|
||||
|
||||
fn = u_strdup(fn);
|
||||
if((n = strrchr(fn, '.')) != NULL) n[0] = 0;
|
||||
|
||||
p = u_strvacat(out, fn, ".html", NULL);
|
||||
if((f = fopen(p, "w")) != NULL){
|
||||
if(!parse_file(top, full)){
|
||||
fclose(f);
|
||||
free(p);
|
||||
free(fn);
|
||||
return 0;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
free(p);
|
||||
|
||||
free(fn);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
14
src/seed.c
14
src/seed.c
|
|
@ -23,9 +23,15 @@ int action_seed(int argc, char** argv){
|
|||
fprintf(f, "<?xml version=\"1.0\"?>\n");
|
||||
fprintf(f, "<skinconfig>\n");
|
||||
fprintf(f, " <search domain=\"example.com\" />\n");
|
||||
fprintf(f, " <vendor>Example Co, Ltd.</vendor>\n");
|
||||
fprintf(f, " <year>2026</vendor>\n");
|
||||
fprintf(f, " <copyright-link>https://example.com</copyright-link>\n");
|
||||
fprintf(f, " <trail>\n");
|
||||
fprintf(f, " <link name=\"Example Co, Ltd\" href=\"https://example.com\" />\n");
|
||||
fprintf(f, " <link name=\"Example Project\" href=\"https://example.com\" />\n");
|
||||
fprintf(f, " </trail>\n");
|
||||
fprintf(f, " <copyright>\n");
|
||||
fprintf(f, " <vendor>Example Co, Ltd.</vendor>\n");
|
||||
fprintf(f, " <year>2026</year>\n");
|
||||
fprintf(f, " <link href=\"https://example.com\">\n");
|
||||
fprintf(f, " </copyright>\n");
|
||||
fprintf(f, "</skinconfig>\n");
|
||||
fclose(f);
|
||||
|
||||
|
|
@ -36,7 +42,7 @@ int action_seed(int argc, char** argv){
|
|||
fprintf(f, "<?xml version=\"1.0\"?>\n");
|
||||
fprintf(f, "<document>\n");
|
||||
fprintf(f, " <header>\n");
|
||||
fprintf(f, " <title>Welcome to template</title>\n");
|
||||
fprintf(f, " <title><![CDATA[Welcome to template]]></title>\n");
|
||||
fprintf(f, " </header>\n");
|
||||
fprintf(f, " <body>\n");
|
||||
fprintf(f, " <section id=\"status\">\n");
|
||||
|
|
|
|||
60
src/site.c
60
src/site.c
|
|
@ -1,6 +1,8 @@
|
|||
#include <taiga.h>
|
||||
|
||||
static void scan(const char* path){
|
||||
xemil_t* skinconf;
|
||||
|
||||
static int scan(const char* top, const char* path){
|
||||
char* in = u_strvacat("site/content/", path, NULL);
|
||||
char* out = u_strvacat("build/", path, NULL);
|
||||
IO_DIR* dir;
|
||||
|
|
@ -19,11 +21,29 @@ static void scan(const char* path){
|
|||
if(io_stat(p, &s) == 0){
|
||||
if(IO_S_ISDIR(s.st_mode)){
|
||||
char* p2 = u_strvacat(d->d_name, "/", NULL);
|
||||
scan(p2);
|
||||
char* t = u_strvacat(top, "../", NULL);
|
||||
if(!scan(t, p2)){
|
||||
free(t);
|
||||
free(p2);
|
||||
free(p);
|
||||
io_closedir(dir);
|
||||
free(out);
|
||||
free(in);
|
||||
|
||||
return 0;
|
||||
}
|
||||
free(t);
|
||||
free(p2);
|
||||
}else if(strcmp(d->d_name, "index.xml") == 0){
|
||||
process(out, p);
|
||||
printf("%s\n", p);
|
||||
printf("%s:\n", p);
|
||||
if(!process(top, out, p)){
|
||||
free(p);
|
||||
io_closedir(dir);
|
||||
free(out);
|
||||
free(in);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(p);
|
||||
|
|
@ -34,12 +54,42 @@ static void scan(const char* path){
|
|||
|
||||
free(out);
|
||||
free(in);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int action_site(int argc, char** argv){
|
||||
int st = 0;
|
||||
FILE* css;
|
||||
|
||||
io_mkdir("build", 0755);
|
||||
|
||||
scan("");
|
||||
if((skinconf = xl_open_file("site/skinconf.xml")) == NULL || !xl_parse(skinconf)){
|
||||
fprintf(stderr, "Failed to parse site/skinconf.xml!\n");
|
||||
st = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if((css = fopen("build/style.css", "w")) == NULL){
|
||||
st = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
classic_stylesheet(css);
|
||||
fclose(css);
|
||||
|
||||
if(!scan("", "")){
|
||||
st = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:;
|
||||
if(skinconf != NULL) xl_close(skinconf);
|
||||
|
||||
if(st == 0){
|
||||
fprintf(stderr, "\nBuild successful\n");
|
||||
}else{
|
||||
fprintf(stderr, "\nBuild failed!\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
11
src/taiga.h
11
src/taiga.h
|
|
@ -15,6 +15,8 @@
|
|||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <xemil.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define io_mkdir(x,y) _mkdir(x)
|
||||
#define io_chdir(x) _chdir(x)
|
||||
|
|
@ -36,6 +38,8 @@
|
|||
#endif
|
||||
|
||||
/* site.c */
|
||||
extern xemil_t* skinconf;
|
||||
|
||||
int action_site(int argc, char** argv);
|
||||
|
||||
/* help.c */
|
||||
|
|
@ -49,6 +53,11 @@ char* u_strvacat(const char* str, ...);
|
|||
char* u_strdup(const char* str);
|
||||
|
||||
/* process.c */
|
||||
void process(const char* out, const char* full);
|
||||
int process(const char* top, const char* out, const char* full);
|
||||
|
||||
/* classic.c */
|
||||
void classic_stylesheet(FILE* out);
|
||||
void classic_head(FILE* out, const char* top, xl_node_t* header);
|
||||
void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue