diff --git a/src/classic.c b/src/classic.c index 553976b..2826c8a 100644 --- a/src/classic.c +++ b/src/classic.c @@ -49,7 +49,7 @@ void classic_stylesheet(FILE* out, const char* top) { fprintf(out, " padding: 8px;\n"); fprintf(out, "}\n"); fprintf(out, "\n"); - fprintf(out, "#content {\n"); + fprintf(out, "#content, #footer {\n"); fprintf(out, " padding: 8px;\n"); fprintf(out, "}\n"); fprintf(out, "\n"); @@ -298,11 +298,25 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body child = body->first_child; while(child != NULL) { - default_body(out, top, child, 6); + default_body(out, top, child, 0, 6); child = child->next; } + fprintf(out, " \n"); + fprintf(out, "
\n"); + + if((nodes = xl_get_path(skinconf->root, "footer")) != NULL) { + child = nodes[0]->first_child; + while(child != NULL) { + default_body(out, top, child, 1, 6); + + child = child->next; + } + + free(nodes); + } + fprintf(out, "
\n"); fprintf(out, " \n"); fprintf(out, " \n"); diff --git a/src/default.c b/src/default.c index 2750f85..618f43b 100644 --- a/src/default.c +++ b/src/default.c @@ -18,7 +18,7 @@ static void print(FILE* out, const char* txt, int indent) { } } -static void accept_attr(char* text, xl_node_t* element, ...) { +static void accept_attr(const char* top, char* text, int spec, xl_node_t* element, ...) { xl_attribute_t* attr = element->first_attribute; text[0] = 0; @@ -33,7 +33,17 @@ static void accept_attr(char* text, xl_node_t* element, ...) { if(attr->value == NULL) { sprintf(text + strlen(text), " %s", attr->key); } else { - sprintf(text + strlen(text), " %s=\"%s\"", attr->key, attr->value); + char* t; + + if(spec && (strcmp(attr->key, "href") == 0 || strcmp(attr->key, "src") == 0)) { + t = u_path(top, attr->value); + } else { + t = u_strdup(attr->value); + } + + sprintf(text + strlen(text), " %s=\"%s\"", attr->key, t); + + free(t); } } va_end(va); @@ -55,7 +65,7 @@ void default_head(FILE* out, const char* top, xl_node_t* element, int indent) { if(strcmp(element->name, "link") == 0) { char text[2048]; - accept_attr(text, element, "rel", "href", NULL); + accept_attr(top, text, 0, element, "rel", "href", NULL); sprintf(tag, "<%s%s>", element->name, text); } @@ -80,7 +90,7 @@ void default_head(FILE* out, const char* top, xl_node_t* element, int indent) { print(out, end, indent); } -void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { +void default_body(FILE* out, const char* top, xl_node_t* element, int spec, int indent) { xl_node_t* child; char tag[2048]; /* enough for most cases... :) */ char end[128]; @@ -104,7 +114,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { author[0] = 0; - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); if(strcmp(element->name, "fixme") == 0) { say = "Fixme"; @@ -153,27 +163,27 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { strcmp(element->name, "h4") == 0 || /**/ strcmp(element->name, "h5") == 0 || /**/ strcmp(element->name, "h6") == 0) { - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "", element->name); } else if(strcmp(element->name, "ul") == 0 || /**/ strcmp(element->name, "ol") == 0) { - accept_attr(text, element, "id", "class", "spacing", NULL); + accept_attr(top, text, 0, element, "id", "class", "spacing", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "", element->name); } else if(strcmp(element->name, "a") == 0) { - accept_attr(text, element, "id", "class", "href", "title", "rel", NULL); + accept_attr(top, text, 0, element, "id", "class", "href", "title", "rel", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "", element->name); } else if(strcmp(element->name, "td") == 0 || /**/ strcmp(element->name, "th") == 0) { - accept_attr(text, element, "id", "class", "rowspan", "colspan", NULL); + accept_attr(top, text, 0, element, "id", "class", "rowspan", "colspan", NULL); sprintf(tag, "<%s%s>", element->name, text); @@ -184,7 +194,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { char* h; int ws, hs; - accept_attr(text, element, "src", "alt", "title", "height", "width", "id", "class", NULL); + accept_attr(top, text, 0, element, "src", "alt", "title", "height", "width", "id", "class", NULL); w = xl_get_attribute(element, "width"); h = xl_get_attribute(element, "height"); @@ -202,20 +212,20 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { sprintf(tag, "<%s%s border=\"0\">", element->name, text); } else if(strcmp(element->name, "script") == 0) { - accept_attr(text, element, "src", "type", NULL); + accept_attr(top, text, 0, element, "src", "type", NULL); sprintf(tag, "<%s%s>", element->name, text); sprintf(end, "", element->name); } else if(strcmp(element->name, "table") == 0) { - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); sprintf(tag, "<%s%s class=\"grid\" width=\"100%%\" cellpadding=\"3\" cellspacing=\"2\" border=\"1\">", element->name, text); sprintf(end, "", element->name); } else if(strcmp(element->name, "hr") == 0 || /**/ strcmp(element->name, "br") == 0) { - accept_attr(text, element, "id", "class", NULL); + accept_attr(top, text, 0, element, "id", "class", NULL); sprintf(tag, "<%s%text>", element->name, text); } @@ -225,7 +235,7 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int indent) { child = element->first_child; while(child != NULL) { if(child->type == XL_NODE_NODE && child->name != NULL) { - default_body(out, top, child, indent + 1 + add); + default_body(out, top, child, spec, indent + 1 + add); } else if(child->type == XL_NODE_TEXT && child->text != NULL) { print(out, child->text, indent + 1 + add); } diff --git a/src/seed.c b/src/seed.c index b681858..3119d49 100644 --- a/src/seed.c +++ b/src/seed.c @@ -54,6 +54,7 @@ int action_seed(int argc, char** argv) { 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, " - This rule applies to footer's src/href too\n"); fprintf(f, "-->\n"); fprintf(f, "\n"); fprintf(f, " \n"); @@ -91,6 +92,9 @@ int action_seed(int argc, char** argv) { fprintf(f, " %d \n", 1900 + tm->tm_year); fprintf(f, " \n"); fprintf(f, " \n"); + fprintf(f, " \n"); fprintf(f, "\n"); fclose(f); diff --git a/src/simple.c b/src/simple.c index 023a0fb..f066d15 100644 --- a/src/simple.c +++ b/src/simple.c @@ -298,12 +298,24 @@ void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body) child = body->first_child; while(child != NULL) { - default_body(out, top, child, 5); + default_body(out, top, child, 0, 5); child = child->next; } fprintf(out, "
\n"); + + if((nodes = xl_get_path(skinconf->root, "footer")) != NULL) { + child = nodes[0]->first_child; + while(child != NULL) { + default_body(out, top, child, 1, 6); + + child = child->next; + } + + free(nodes); + } + fprintf(out, " \"Valid\n", top); fprintf(out, " \"Valid\n", top); fprintf(out, "

\n"); diff --git a/src/site.c b/src/site.c index 06becf5..fdb3292 100644 --- a/src/site.c +++ b/src/site.c @@ -90,7 +90,7 @@ int action_site(int argc, char** argv) { io_mkdir("build", 0755); - if((skinconf = xl_open_file("site/skinconf.xml")) == NULL || !xl_parse(skinconf)) { + if((skinconf = xl_open_file("site/skinconf.xml")) == NULL || !(skinconf->new_text = 1) || !xl_parse(skinconf)) { fprintf(stderr, "Failed to parse site/skinconf.xml!\n"); st = 1; goto cleanup; diff --git a/src/taiga.h b/src/taiga.h index 2ed19f4..e678179 100644 --- a/src/taiga.h +++ b/src/taiga.h @@ -71,6 +71,17 @@ int u_image_size(const char* top, const char* path, char* (*path_func)(const c /* process.c */ int process(const char* top, const char* out, const char* full); +/* default.c */ +void default_head(FILE* out, const char* top, xl_node_t* element, int indent); +void default_body(FILE* out, const char* top, xl_node_t* element, int spec, int indent); /* pass non-zero to spec if you want links to be relative from top */ +void default_nav(FILE* out, const char* top, xl_node_t* element, int indent); + +/*** skins ***/ + +/* they should share compatible class/id names for elements but + * they're not documented... oh well + */ + /* classic.c */ void classic_stylesheet(FILE* out, const char* top); void classic_head(FILE* out, const char* top, xl_node_t* header); @@ -81,9 +92,4 @@ 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); -void default_body(FILE* out, const char* top, xl_node_t* element, int indent); -void default_nav(FILE* out, const char* top, xl_node_t* element, int indent); - #endif