This commit is contained in:
parent
994d354bd6
commit
55aa66a7db
12 changed files with 143 additions and 209 deletions
20
.clang-format
Normal file
20
.clang-format
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
Language: Cpp
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
IndentWidth: 8
|
||||
PointerAlignment: Left
|
||||
ColumnLimit: 0
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
SpaceBeforeParens: Never
|
||||
AlignEscapedNewlines: DontAlign
|
||||
SortIncludes: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
#IndentPPDirectives: AfterHash
|
||||
2
external/xemil
vendored
2
external/xemil
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 178fe4aca775436db87de22765d5dcb52325981c
|
||||
Subproject commit 750c29566540c46f5a480beb1e4abe032d6a0484
|
||||
3
objs.mk
3
objs.mk
|
|
@ -59,6 +59,9 @@ src/src_process.o: src/process.c
|
|||
OBJS += src/src_seed.o
|
||||
src/src_seed.o: src/seed.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/seed.c
|
||||
OBJS += src/src_simple.o
|
||||
src/src_simple.o: src/simple.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/simple.c
|
||||
OBJS += src/src_site.o
|
||||
src/src_site.o: src/site.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/site.c
|
||||
|
|
|
|||
124
src/classic.c
124
src/classic.c
|
|
@ -17,8 +17,7 @@ void classic_stylesheet(FILE* out, const char* top) {
|
|||
|
||||
free(nodes);
|
||||
}
|
||||
if(breadcrumb_bgcolor == NULL)
|
||||
breadcrumb_bgcolor = "#003366";
|
||||
if(breadcrumb_bgcolor == NULL) breadcrumb_bgcolor = "#003366";
|
||||
|
||||
fprintf(out, "body {\n");
|
||||
fprintf(out, " padding: 0;\n");
|
||||
|
|
@ -130,8 +129,7 @@ void classic_stylesheet(FILE* out, const char* top) {
|
|||
void classic_head(FILE* out, const char* top, xl_node_t* header) {
|
||||
xl_node_t* child;
|
||||
|
||||
fprintf(out, " <link rel=\"stylesheet\" href=\"%sstyle.css\">\n",
|
||||
top);
|
||||
fprintf(out, " <link rel=\"stylesheet\" href=\"%sstyle.css\">\n", top);
|
||||
|
||||
child = header->first_child;
|
||||
while(child != NULL) {
|
||||
|
|
@ -141,10 +139,8 @@ 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) {
|
||||
char year[4 + 1 + 4 +
|
||||
1]; /* no one would use our software in year 10000... right? :) */
|
||||
void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body) {
|
||||
char year[4 + 1 + 4 + 1]; /* no one would use our software in year 10000... right? :) */
|
||||
char* holder = "Unknown people";
|
||||
char* sitesearch = NULL;
|
||||
xl_node_t** nodes;
|
||||
|
|
@ -189,8 +185,7 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
if(sitesearch == NULL)
|
||||
sitesearch = "https://invalid.link";
|
||||
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" "
|
||||
"cellspacing=\"0\" width=\"100%%\">\n");
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%%\">\n");
|
||||
fprintf(out, " <tr width=\"100%%\">\n");
|
||||
fprintf(out, " <td>\n");
|
||||
for(i = 0; i < sizeof(images) / sizeof(images[0]); i++) {
|
||||
|
|
@ -203,16 +198,14 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
name = nodes[0]->text;
|
||||
free(nodes);
|
||||
}
|
||||
if(name == NULL)
|
||||
name = "Logo";
|
||||
if(name == NULL) name = "Logo";
|
||||
|
||||
sprintf(path, "%s.link", images[i]);
|
||||
if((nodes = xl_get_path(skinconf->root, path)) != NULL) {
|
||||
link = xl_get_attribute(nodes[0], "href");
|
||||
free(nodes);
|
||||
}
|
||||
if(link == NULL)
|
||||
link = "https://invalid.link";
|
||||
if(link == NULL) link = "https://invalid.link";
|
||||
|
||||
link = u_path(top, link);
|
||||
|
||||
|
|
@ -222,10 +215,7 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
|
||||
if(text != NULL) {
|
||||
text = u_path(top, text);
|
||||
fprintf(out,
|
||||
" <a href=\"%s\"><img "
|
||||
"src=\"%s\" alt=\"%s\" border=\"0\"></a>\n",
|
||||
link, text, images[i + 1], name);
|
||||
fprintf(out, " <a href=\"%s\"><img src=\"%s\" alt=\"%s\" border=\"0\"></a>\n", link, text, images[i + 1], name);
|
||||
free(text);
|
||||
}
|
||||
|
||||
|
|
@ -237,8 +227,7 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
fprintf(out, " </td>\n");
|
||||
fprintf(out, " </tr>\n");
|
||||
fprintf(out, " </table>\n");
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" "
|
||||
"cellspacing=\"0\" width=\"100%%\" id=\"breadcrumb\">\n");
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%%\" id=\"breadcrumb\">\n");
|
||||
fprintf(out, " <tr width=\"100%%\">\n");
|
||||
fprintf(out, " <td>\n");
|
||||
if((nodes = xl_get_path(skinconf->root, "breadcrumb.link")) != NULL) {
|
||||
|
|
@ -248,18 +237,14 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
char* link = xl_get_attribute(nodes[i], "href");
|
||||
char* name = xl_get_attribute(nodes[i], "name");
|
||||
|
||||
if(link == NULL)
|
||||
link = "https://invalid.link";
|
||||
if(link == NULL) link = "https://invalid.link";
|
||||
|
||||
link = u_path(top, link);
|
||||
|
||||
if(title == NULL)
|
||||
title = link;
|
||||
if(title == NULL) title = link;
|
||||
|
||||
if(i > 0)
|
||||
fprintf(out, " |\n");
|
||||
fprintf(out, " <a href=\"%s\">%s</a>\n",
|
||||
link, name);
|
||||
if(i > 0) fprintf(out, " |\n");
|
||||
fprintf(out, " <a href=\"%s\">%s</a>\n", link, name);
|
||||
|
||||
free(link);
|
||||
}
|
||||
|
|
@ -267,28 +252,19 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
free(nodes);
|
||||
}
|
||||
fprintf(out, " </td>\n");
|
||||
fprintf(out, " <td nowrap=\"1\" "
|
||||
"align=\"right\">\n");
|
||||
fprintf(out, " <form "
|
||||
"action=\"https://www.google.com/search\" method=\"GET\">\n");
|
||||
fprintf(out, " <td nowrap=\"1\" align=\"right\">\n");
|
||||
fprintf(out, " <form action=\"https://www.google.com/search\" method=\"GET\">\n");
|
||||
fprintf(out, " Search\n");
|
||||
fprintf(out,
|
||||
" <input type=\"hidden\" "
|
||||
"name=\"sitesearch\" value=\"%s\">\n",
|
||||
sitesearch);
|
||||
fprintf(out, " <input "
|
||||
"name=\"q\" size=\"10\">\n");
|
||||
fprintf(out, " <input "
|
||||
"type=\"submit\" value=\"Go\">\n");
|
||||
fprintf(out, " <input type=\"hidden\" name=\"sitesearch\" value=\"%s\">\n", sitesearch);
|
||||
fprintf(out, " <input name=\"q\" size=\"10\">\n");
|
||||
fprintf(out, " <input type=\"submit\" value=\"Go\">\n");
|
||||
fprintf(out, " </form>\n");
|
||||
fprintf(out, " </td>\n");
|
||||
fprintf(out, " </tr>\n");
|
||||
fprintf(out, " </table>\n");
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" "
|
||||
"cellspacing=\"0\" width=\"100%%\">\n");
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%%\">\n");
|
||||
fprintf(out, " <tr>\n");
|
||||
fprintf(out, " <td width=\"150\" "
|
||||
"valign=\"top\">\n");
|
||||
fprintf(out, " <td width=\"150\" valign=\"top\">\n");
|
||||
fprintf(out, " <div id=\"nav\">\n");
|
||||
|
||||
if((nodes = xl_get_path(skinconf->root, "nav")) != NULL) {
|
||||
|
|
@ -307,8 +283,7 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
fprintf(out, " </div>\n");
|
||||
fprintf(out, " </td>\n");
|
||||
fprintf(out, " <td valign=\"top\">\n");
|
||||
fprintf(out, " <div "
|
||||
"id=\"content\">\n");
|
||||
fprintf(out, " <div id=\"content\">\n");
|
||||
|
||||
child = body->first_child;
|
||||
while(child != NULL) {
|
||||
|
|
@ -321,62 +296,31 @@ void classic_body(FILE* out, const char* top, const char* title,
|
|||
fprintf(out, " </td>\n");
|
||||
fprintf(out, " </tr>\n");
|
||||
fprintf(out, " </table>\n");
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" "
|
||||
"cellspacing=\"0\" width=\"100%%\">\n");
|
||||
fprintf(out, " <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%%\">\n");
|
||||
fprintf(out, " <tr>\n");
|
||||
fprintf(
|
||||
out,
|
||||
" <td id=\"copyright\" align=\"center\">\n");
|
||||
fprintf(out,
|
||||
" Copyright © %s %s%s All "
|
||||
"rights reserved.\n",
|
||||
year, holder,
|
||||
(strlen(holder) > 0 && holder[strlen(holder) - 1] == '.') ? "" : ".");
|
||||
fprintf(out, " <td id=\"copyright\" align=\"center\">\n");
|
||||
fprintf(out, " Copyright © %s %s%s All rights reserved.\n", year, holder, (strlen(holder) > 0 && holder[strlen(holder) - 1] == '.') ? "" : ".");
|
||||
fprintf(out, " <td>\n");
|
||||
fprintf(out, " </tr>\n");
|
||||
fprintf(out, " <tr>\n");
|
||||
fprintf(out, " <td align=\"right\">\n");
|
||||
fprintf(out,
|
||||
" <a "
|
||||
"href=\"https://validator.w3.org/check/referer\"><img "
|
||||
"src=\"%simage/valid-html401.png\" alt=\"Valid HTML 4.01\" "
|
||||
"border=\"0\"></a>\n",
|
||||
top);
|
||||
fprintf(out,
|
||||
" <a "
|
||||
"href=\"https://jigsaw.w3.org/css-validator/\"><img "
|
||||
"src=\"%simage/valid-css.png\" alt=\"Valid CSS\" border=\"0\"></a>\n",
|
||||
top);
|
||||
fprintf(out, " <a href=\"https://validator.w3.org/check/referer\"><img src=\"%simage/valid-html401.png\" alt=\"Valid HTML 4.01\" border=\"0\"></a>\n", top);
|
||||
fprintf(out, " <a href=\"https://jigsaw.w3.org/css-validator/\"><img src=\"%simage/valid-css.png\" alt=\"Valid CSS\" border=\"0\"></a>\n", top);
|
||||
fprintf(out, " <td>\n");
|
||||
fprintf(out, " </tr>\n");
|
||||
fprintf(out, " </table>\n");
|
||||
fprintf(out, " <!--[if lte IE 6]>\n");
|
||||
fprintf(
|
||||
out,
|
||||
" <script language=\"javascript\" type=\"text/javascript\">\n");
|
||||
fprintf(
|
||||
out,
|
||||
" for(var i = 0; i < document.images.length; i++){\n");
|
||||
fprintf(out, " var s = "
|
||||
"document.images[i].src;\n");
|
||||
fprintf(out, " <script language=\"javascript\" type=\"text/javascript\">\n");
|
||||
fprintf(out, " for(var i = 0; i < document.images.length; i++){\n");
|
||||
fprintf(out, " var s = document.images[i].src;\n");
|
||||
fprintf(out, " if(s.indexOf('.png') > 0){\n");
|
||||
fprintf(out, " var oldw = "
|
||||
"document.images[i].clientWidth;\n");
|
||||
fprintf(out, " var oldh = "
|
||||
"document.images[i].clientHeight;\n");
|
||||
fprintf(out,
|
||||
" document.images[i].src = "
|
||||
"'%simage/fill.gif';\n",
|
||||
top);
|
||||
fprintf(
|
||||
out,
|
||||
" document.images[i].style.filter = "
|
||||
"\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='\" + s + \"', "
|
||||
"sizingMethod='scale')\";\n");
|
||||
fprintf(out, " var oldw = document.images[i].clientWidth;\n");
|
||||
fprintf(out, " var oldh = document.images[i].clientHeight;\n");
|
||||
fprintf(out, " document.images[i].src = '%simage/fill.gif';\n", top);
|
||||
fprintf(out, " document.images[i].style.filter = \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='\" + s + \"', sizingMethod='scale')\";\n");
|
||||
fprintf(out, " "
|
||||
"document.images[i].style.width = oldw + \"px\";\n");
|
||||
fprintf(out, " "
|
||||
"document.images[i].style.height = oldh + \"px\";\n");
|
||||
fprintf(out, " document.images[i].style.height = oldh + \"px\";\n");
|
||||
fprintf(out, " }\n");
|
||||
fprintf(out, " }\n");
|
||||
fprintf(out, " </script>\n");
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ static void print(FILE* out, const char* txt, int indent) {
|
|||
fprintf(out, "\t");
|
||||
}
|
||||
|
||||
if(txt[i] != '\n')
|
||||
fprintf(out, "%c", txt[i]);
|
||||
if(txt[i] != '\n') fprintf(out, "%c", txt[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,8 +50,7 @@ void default_head(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
|
||||
tag[0] = end[0] = 0;
|
||||
|
||||
if(element->name == NULL)
|
||||
return;
|
||||
if(element->name == NULL) return;
|
||||
|
||||
if(strcmp(element->name, "link") == 0) {
|
||||
char text[2048];
|
||||
|
|
@ -62,8 +60,7 @@ void default_head(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
sprintf(tag, "<%s%s>", element->name, text);
|
||||
}
|
||||
|
||||
if(tag[0] != 0)
|
||||
print(out, tag, indent);
|
||||
if(tag[0] != 0) print(out, tag, indent);
|
||||
|
||||
child = element->first_child;
|
||||
while(child != NULL) {
|
||||
|
|
@ -92,8 +89,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
|
||||
tag[0] = end[0] = 0;
|
||||
|
||||
if(element->name == NULL)
|
||||
return;
|
||||
if(element->name == NULL) return;
|
||||
|
||||
if(strcmp(element->name, "section") == 0) {
|
||||
char* title = xl_get_attribute(element, "title");
|
||||
|
|
@ -114,28 +110,21 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
say = "Fixme";
|
||||
|
||||
strcpy(author, " ()");
|
||||
if((attr = xl_get_attribute(element, "author")) != NULL)
|
||||
sprintf(author, " (%s)", attr);
|
||||
if((attr = xl_get_attribute(element, "author")) != NULL) sprintf(author, " (%s)", attr);
|
||||
} else if(strcmp(element->name, "warning") == 0) {
|
||||
say = "Warning";
|
||||
} else if(strcmp(element->name, "note") == 0) {
|
||||
say = "Note";
|
||||
}
|
||||
|
||||
sprintf(tag + strlen(tag), "<div class=\"%s-message\"%s>\n", element->name,
|
||||
text);
|
||||
sprintf(tag + strlen(tag), " <table border=\"0\" cellpadding=\"0\" "
|
||||
"cellspacing=\"0\" width=\"100%%\">\n");
|
||||
sprintf(tag + strlen(tag), "<div class=\"%s-message\"%s>\n", element->name, text);
|
||||
sprintf(tag + strlen(tag), " <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%%\">\n");
|
||||
sprintf(tag + strlen(tag), " <tr>\n");
|
||||
sprintf(tag + strlen(tag),
|
||||
" <td rowspan=\"2\" class=\"message-icon\">\n");
|
||||
sprintf(tag + strlen(tag),
|
||||
" <img src=\"%simage/%s.png\">\n", top,
|
||||
element->name);
|
||||
sprintf(tag + strlen(tag), " <td rowspan=\"2\" class=\"message-icon\">\n");
|
||||
sprintf(tag + strlen(tag), " <img src=\"%simage/%s.png\">\n", top, element->name);
|
||||
sprintf(tag + strlen(tag), " </td>\n");
|
||||
sprintf(tag + strlen(tag), " <td>\n");
|
||||
sprintf(tag + strlen(tag), " <b>%s%s</b>\n", say,
|
||||
author);
|
||||
sprintf(tag + strlen(tag), " <b>%s%s</b>\n", say, author);
|
||||
sprintf(tag + strlen(tag), " </td>\n");
|
||||
sprintf(tag + strlen(tag), " </tr>\n");
|
||||
sprintf(tag + strlen(tag), " <tr>\n");
|
||||
|
|
@ -199,10 +188,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
} else if(strcmp(element->name, "table") == 0) {
|
||||
accept_attr(text, element, "id", "class", NULL);
|
||||
|
||||
sprintf(tag,
|
||||
"<%s%s class=\"grid\" width=\"100%%\" cellpadding=\"3\" "
|
||||
"cellspacing=\"2\" border=\"1\">",
|
||||
element->name, text);
|
||||
sprintf(tag, "<%s%s class=\"grid\" width=\"100%%\" cellpadding=\"3\" cellspacing=\"2\" border=\"1\">", element->name, text);
|
||||
|
||||
sprintf(end, "</%s>", element->name);
|
||||
} else if(strcmp(element->name, "hr") == 0 || /**/
|
||||
|
|
@ -212,8 +198,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
sprintf(tag, "<%s%text>", element->name, text);
|
||||
}
|
||||
|
||||
if(tag[0] != 0)
|
||||
print(out, tag, indent);
|
||||
if(tag[0] != 0) print(out, tag, indent);
|
||||
|
||||
child = element->first_child;
|
||||
while(child != NULL) {
|
||||
|
|
@ -226,29 +211,24 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
child = child->next;
|
||||
}
|
||||
|
||||
if(end[0] != 0)
|
||||
print(out, end, indent);
|
||||
if(end[0] != 0) print(out, end, indent);
|
||||
}
|
||||
|
||||
void default_nav(FILE* out, const char* top, xl_node_t* element, int indent) {
|
||||
int i;
|
||||
|
||||
if(element->name == NULL)
|
||||
return;
|
||||
if(element->name == NULL) return;
|
||||
|
||||
if(strcmp(element->name, "link") == 0) {
|
||||
char* link;
|
||||
char* name;
|
||||
|
||||
if((link = xl_get_attribute(element, "href")) == NULL)
|
||||
link = "https://invalid.link";
|
||||
if((name = xl_get_attribute(element, "name")) == NULL)
|
||||
name = "";
|
||||
if((link = xl_get_attribute(element, "href")) == NULL) link = "https://invalid.link";
|
||||
if((name = xl_get_attribute(element, "name")) == NULL) name = "";
|
||||
|
||||
link = u_path(top, link);
|
||||
|
||||
for(i = 0; i < indent; i++)
|
||||
fprintf(out, "\t");
|
||||
for(i = 0; i < indent; i++) fprintf(out, "\t");
|
||||
fprintf(out, " - <a href=\"%s\">%s</a><br>\n", link, name);
|
||||
|
||||
free(link);
|
||||
|
|
@ -256,17 +236,14 @@ void default_nav(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
char* title;
|
||||
xl_node_t* child;
|
||||
|
||||
if((title = xl_get_attribute(element, "title")) == NULL)
|
||||
title = "";
|
||||
if((title = xl_get_attribute(element, "title")) == NULL) title = "";
|
||||
|
||||
if(title != NULL) {
|
||||
for(i = 0; i < indent; i++)
|
||||
fprintf(out, "\t");
|
||||
for(i = 0; i < indent; i++) fprintf(out, "\t");
|
||||
fprintf(out, "<div class=\"linkgrouptitle\"> - %s</div>\n", title);
|
||||
}
|
||||
|
||||
for(i = 0; i < indent; i++)
|
||||
fprintf(out, "\t");
|
||||
for(i = 0; i < indent; i++) fprintf(out, "\t");
|
||||
fprintf(out, "<div class=\"linkgroup\">\n");
|
||||
|
||||
child = element->first_child;
|
||||
|
|
@ -276,8 +253,7 @@ void default_nav(FILE* out, const char* top, xl_node_t* element, int indent) {
|
|||
child = child->next;
|
||||
}
|
||||
|
||||
for(i = 0; i < indent; i++)
|
||||
fprintf(out, "\t");
|
||||
for(i = 0; i < indent; i++) fprintf(out, "\t");
|
||||
fprintf(out, "</div>\n");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
src/main.c
12
src/main.c
|
|
@ -7,16 +7,13 @@ int main(int argc, char** argv) {
|
|||
char** target_argv = malloc(sizeof(*target_argv));
|
||||
target_argv[0] = NULL;
|
||||
|
||||
printf("Taiga, static website generator - run `%s help' for help\n\n",
|
||||
argv[0]);
|
||||
printf("Taiga, static website generator - run `%s help' for help\n\n", argv[0]);
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
if(argv[i][0] == '-') {
|
||||
if(action != NULL)
|
||||
continue;
|
||||
if(action != NULL) continue;
|
||||
} else {
|
||||
if(action != NULL)
|
||||
continue;
|
||||
if(action != NULL) continue;
|
||||
action = argv[i];
|
||||
|
||||
free(target_argv);
|
||||
|
|
@ -25,8 +22,7 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
}
|
||||
|
||||
if(action == NULL)
|
||||
action = "site";
|
||||
if(action == NULL) action = "site";
|
||||
|
||||
if(strcmp(action, "site") == 0) {
|
||||
return action_site(target_argc, target_argv);
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ static int parse_file(const char* top, const char* full) {
|
|||
xl_node_t** nodes2;
|
||||
int has_own_icon = 0;
|
||||
|
||||
if(handle->root != NULL)
|
||||
node = handle->root->first_child;
|
||||
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;
|
||||
|
|
@ -39,8 +38,7 @@ static int parse_file(const char* top, const char* full) {
|
|||
}
|
||||
|
||||
header = node;
|
||||
} else if(node->type == XL_NODE_NODE &&
|
||||
strcmp(node->name, "body") == 0) {
|
||||
} else if(node->type == XL_NODE_NODE && strcmp(node->name, "body") == 0) {
|
||||
body = node;
|
||||
}
|
||||
|
||||
|
|
@ -50,13 +48,10 @@ static int parse_file(const char* top, const char* full) {
|
|||
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, "<!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, " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n");
|
||||
fprintf(f, " <title>%s</title>\n", title);
|
||||
|
||||
if((nodes = xl_get_path(header, "link")) != NULL) {
|
||||
|
|
@ -74,10 +69,9 @@ static int parse_file(const char* top, const char* full) {
|
|||
free(nodes);
|
||||
}
|
||||
|
||||
classic_head(f, top, header);
|
||||
site_head(f, top, header);
|
||||
|
||||
if(!has_own_icon &&
|
||||
(nodes = xl_get_path(skinconf->root, "favicon")) != NULL) {
|
||||
if(!has_own_icon && (nodes = xl_get_path(skinconf->root, "favicon")) != NULL) {
|
||||
if(nodes[0]->text != NULL) {
|
||||
char* p = u_path(top, nodes[0]->text);
|
||||
fprintf(f, " <link rel=\"icon\" href=\"%s\">\n", p);
|
||||
|
|
@ -89,7 +83,7 @@ static int parse_file(const char* top, const char* full) {
|
|||
|
||||
fprintf(f, " </head>\n");
|
||||
fprintf(f, " <body>\n");
|
||||
classic_body(f, top, title, body);
|
||||
site_body(f, top, title, body);
|
||||
fprintf(f, " </body>\n");
|
||||
fprintf(f, "</html>\n");
|
||||
|
||||
|
|
@ -100,8 +94,7 @@ static int parse_file(const char* top, const char* full) {
|
|||
st = 0;
|
||||
}
|
||||
|
||||
if(handle != NULL)
|
||||
xl_close(handle);
|
||||
if(handle != NULL) xl_close(handle);
|
||||
|
||||
return st;
|
||||
}
|
||||
|
|
@ -109,16 +102,14 @@ static int parse_file(const char* top, const char* full) {
|
|||
int process(const char* top, const char* out, const char* full) {
|
||||
char* fn = strrchr(full, '/');
|
||||
|
||||
if(fn != NULL)
|
||||
fn = fn + 1;
|
||||
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;
|
||||
if((n = strrchr(fn, '.')) != NULL) n[0] = 0;
|
||||
|
||||
p = u_strvacat(out, fn, ".html", NULL);
|
||||
if((f = fopen(p, "w")) != NULL) {
|
||||
|
|
|
|||
39
src/seed.c
39
src/seed.c
|
|
@ -14,8 +14,7 @@ static void describe(const char* path, const char* what) {
|
|||
int i;
|
||||
|
||||
memset(space, 0, sizeof(space));
|
||||
for(i = 0; i < (48 - strlen(path)); i++)
|
||||
space[i] = ' ';
|
||||
for(i = 0; i < (48 - strlen(path)); i++) space[i] = ' ';
|
||||
|
||||
printf("%s%s# %s\n", path, space, what);
|
||||
}
|
||||
|
|
@ -53,45 +52,34 @@ int action_seed(int argc, char** argv) {
|
|||
fprintf(f, "<?xml version=\"1.0\"?>\n");
|
||||
fprintf(f, "<!--\n");
|
||||
fprintf(f, " NOTE!\n");
|
||||
fprintf(
|
||||
f,
|
||||
" - Relative path in this config is relative to site/content\n");
|
||||
fprintf(f, " - If relative path starts from ./ or ../, it's relative to "
|
||||
"URL when accessed\n");
|
||||
fprintf(f, " - Relative path in this config is relative to site/content\n");
|
||||
fprintf(f, " - If relative path starts from ./ or ../, it's relative to URL when accessed\n");
|
||||
fprintf(f, "-->\n");
|
||||
fprintf(f, "<skinconfig>\n");
|
||||
fprintf(f, " <search domain=\"example.com\" />\n");
|
||||
fprintf(f, " <breadcrumb>\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, " <link name=\"Example Co, Ltd\" href=\"https://example.com\" />\n");
|
||||
fprintf(f, " <link name=\"Example Project\" href=\"https://example.com\" />\n");
|
||||
fprintf(f, " </breadcrumb>\n");
|
||||
fprintf(f, " <group>\n");
|
||||
fprintf(f, " <name>Example Co, Ltd</name>\n");
|
||||
fprintf(
|
||||
f,
|
||||
" <description>Example Co, Ltd Description</description>\n");
|
||||
fprintf(f, " <description>Example Co, Ltd Description</description>\n");
|
||||
fprintf(f, " <link href=\"https://example.com\" />\n");
|
||||
fprintf(f, " <image src=\"image/group-logo.png\" />\n");
|
||||
fprintf(f, " </group>\n");
|
||||
fprintf(f, " <project>\n");
|
||||
fprintf(f, " <name>Example Project</name>\n");
|
||||
fprintf(
|
||||
f,
|
||||
" <description>Example Project Description</description>\n");
|
||||
fprintf(f, " <description>Example Project Description</description>\n");
|
||||
fprintf(f, " <link href=\"https://example.com\" />\n");
|
||||
fprintf(f, " <image src=\"image/project-logo.png\" />\n");
|
||||
fprintf(f, " </project>\n");
|
||||
fprintf(f, " <nav>\n");
|
||||
fprintf(f, " <group title=\"Example Project\">\n");
|
||||
fprintf(f, " <link name=\"Home\" href=\"/\" />\n");
|
||||
fprintf(f, " <link name=\"Example Co, Ltd.\" "
|
||||
"href=\"https://example.com\" />\n");
|
||||
fprintf(f, " <link name=\"Example Co, Ltd.\" href=\"https://example.com\" />\n");
|
||||
fprintf(f, " <group title=\"Example Project\">\n");
|
||||
fprintf(f, " <link name=\"Home\" href=\"/\" />\n");
|
||||
fprintf(f, " <link name=\"Example Co, Ltd.\" "
|
||||
"href=\"https://example.com\" />\n");
|
||||
fprintf(f, " <link name=\"Example Co, Ltd.\" href=\"https://example.com\" />\n");
|
||||
fprintf(f, " </group>\n");
|
||||
fprintf(f, " </group>\n");
|
||||
fprintf(f, " </nav>\n");
|
||||
|
|
@ -129,12 +117,9 @@ int action_seed(int argc, char** argv) {
|
|||
fprintf(f, " </table>\n");
|
||||
fprintf(f, " <section title=\"Congratulations\">\n");
|
||||
fprintf(f, " <p>\n");
|
||||
fprintf(f, " You have successfully generated and "
|
||||
"rendered a website using Taiga - static website generator.\n");
|
||||
fprintf(f, " This page is from the site template. "
|
||||
"It is found in <code>site/content/index.xml</code>.\n");
|
||||
fprintf(f, " Please edit it and replace this text "
|
||||
"with content of your own.\n");
|
||||
fprintf(f, " You have successfully generated and rendered a website using Taiga - static website generator.\n");
|
||||
fprintf(f, " This page is from the site template. It is found in <code>site/content/index.xml</code>.\n");
|
||||
fprintf(f, " Please edit it and replace this text with content of your own.\n");
|
||||
fprintf(f, " </p>\n");
|
||||
fprintf(f, " </section>\n");
|
||||
fprintf(f, " </body>\n");
|
||||
|
|
|
|||
10
src/simple.c
Normal file
10
src/simple.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <taiga.h>
|
||||
|
||||
void simple_stylesheet(FILE* out, const char* top) {
|
||||
}
|
||||
|
||||
void simple_head(FILE* out, const char* top, xl_node_t* header) {
|
||||
}
|
||||
|
||||
void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body) {
|
||||
}
|
||||
18
src/site.c
18
src/site.c
|
|
@ -1,6 +1,9 @@
|
|||
#include <taiga.h>
|
||||
|
||||
xemil_t* skinconf;
|
||||
void (*site_stylesheet)(FILE* out, const char* top); /* also create files here if you need one */
|
||||
void (*site_head)(FILE* out, const char* top, xl_node_t* header);
|
||||
void (*site_body)(FILE* out, const char* top, const char* title, xl_node_t* body);
|
||||
|
||||
static int scan(const char* top, const char* path) {
|
||||
char* in = u_strvacat("site/content/", path, NULL);
|
||||
|
|
@ -15,8 +18,7 @@ static int scan(const char* top, const char* path) {
|
|||
char* p;
|
||||
struct io_stat s;
|
||||
|
||||
if(strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
|
||||
continue;
|
||||
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) {
|
||||
|
|
@ -76,12 +78,19 @@ static int scan(const char* top, const char* path) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
#define USE_THEME(x) \
|
||||
site_stylesheet = x##_stylesheet; \
|
||||
site_head = x##_head; \
|
||||
site_body = x##_body;
|
||||
|
||||
int action_site(int argc, char** argv) {
|
||||
int st = 0;
|
||||
FILE* css;
|
||||
|
||||
io_mkdir("build", 0755);
|
||||
|
||||
USE_THEME(simple);
|
||||
|
||||
if((skinconf = xl_open_file("site/skinconf.xml")) == NULL ||
|
||||
!xl_parse(skinconf)) {
|
||||
fprintf(stderr, "Failed to parse site/skinconf.xml!\n");
|
||||
|
|
@ -93,7 +102,7 @@ int action_site(int argc, char** argv) {
|
|||
st = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
classic_stylesheet(css, "build/");
|
||||
site_stylesheet(css, "build/");
|
||||
fclose(css);
|
||||
|
||||
if(!scan("", "")) {
|
||||
|
|
@ -102,8 +111,7 @@ int action_site(int argc, char** argv) {
|
|||
}
|
||||
|
||||
cleanup:;
|
||||
if(skinconf != NULL)
|
||||
xl_close(skinconf);
|
||||
if(skinconf != NULL) xl_close(skinconf);
|
||||
|
||||
if(st == 0) {
|
||||
fprintf(stderr, "\nBuild successful\n");
|
||||
|
|
|
|||
14
src/taiga.h
14
src/taiga.h
|
|
@ -49,6 +49,9 @@ void io_closedir(IO_DIR* dir);
|
|||
|
||||
/* site.c */
|
||||
extern xemil_t* skinconf;
|
||||
extern void (*site_stylesheet)(FILE* out, const char* top); /* also create files here if you need one */
|
||||
extern void (*site_head)(FILE* out, const char* top, xl_node_t* header);
|
||||
extern void (*site_body)(FILE* out, const char* top, const char* title, xl_node_t* body);
|
||||
|
||||
int action_site(int argc, char** argv);
|
||||
|
||||
|
|
@ -67,11 +70,14 @@ char* u_path(const char* top, const char* path);
|
|||
int process(const char* top, const char* out, const char* full);
|
||||
|
||||
/* classic.c */
|
||||
void classic_stylesheet(
|
||||
FILE* out, const char* top); /* also create files here if you need one */
|
||||
void classic_stylesheet(FILE* out, const char* top);
|
||||
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);
|
||||
void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body);
|
||||
|
||||
/* simple.c */
|
||||
void simple_stylesheet(FILE* out, const char* top);
|
||||
void simple_head(FILE* out, const char* top, xl_node_t* header);
|
||||
void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body);
|
||||
|
||||
/* default.c */
|
||||
void default_head(FILE* out, const char* top, xl_node_t* element, int indent);
|
||||
|
|
|
|||
15
src/util.c
15
src/util.c
|
|
@ -8,16 +8,14 @@ char* u_strvacat(const char* str, ...) {
|
|||
|
||||
len += strlen(str);
|
||||
va_start(va, str);
|
||||
while((s = va_arg(va, const char*)) != NULL)
|
||||
len += strlen(s);
|
||||
while((s = va_arg(va, const char*)) != NULL) len += strlen(s);
|
||||
va_end(va);
|
||||
|
||||
r = malloc(len + 1);
|
||||
|
||||
strcpy(r, str);
|
||||
va_start(va, str);
|
||||
while((s = va_arg(va, const char*)) != NULL)
|
||||
strcat(r, s);
|
||||
while((s = va_arg(va, const char*)) != NULL) strcat(r, s);
|
||||
va_end(va);
|
||||
|
||||
return r;
|
||||
|
|
@ -32,12 +30,9 @@ char* u_strdup(const char* str) {
|
|||
}
|
||||
|
||||
char* u_path(const char* top, const char* path) {
|
||||
if(strlen(path) > 3 && strstr(path, "://") != NULL)
|
||||
return u_strdup(path); /* link - return as is */
|
||||
if(strlen(path) > 2 && memcmp(path, "./", 2) == 0)
|
||||
return u_strdup(path); /* current directory - probably intended */
|
||||
if(strlen(path) > 3 && memcmp(path, "../", 2) == 0)
|
||||
return u_strdup(path); /* parent directory - also probably intended */
|
||||
if(strlen(path) > 3 && strstr(path, "://") != NULL) return u_strdup(path); /* link - return as is */
|
||||
if(strlen(path) > 2 && memcmp(path, "./", 2) == 0) return u_strdup(path); /* current directory - probably intended */
|
||||
if(strlen(path) > 3 && memcmp(path, "../", 2) == 0) return u_strdup(path); /* parent directory - also probably intended */
|
||||
|
||||
return u_strvacat(top, path, NULL); /* otherwise, concat */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue