add footer
All checks were successful
pyrite-dev/taiga/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-03-09 02:15:55 +09:00
commit bce3ce55ec
Signed by: nishi
GPG key ID: 27EF69B208EB9343
6 changed files with 69 additions and 23 deletions

View file

@ -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, " </div>\n");
fprintf(out, " <div id=\"footer\">\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, " </div>\n");
fprintf(out, " </td>\n");
fprintf(out, " </tr>\n");

View file

@ -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, "</%s>", 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, "</%s>", 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, "</%s>", 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, "</%s>", 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, "</%s>", 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);
}

View file

@ -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, "<skinconfig>\n");
fprintf(f, " <search domain=\"example.com\" />\n");
@ -91,6 +92,9 @@ int action_seed(int argc, char** argv) {
fprintf(f, " <year>%d</year> <!-- Year when you started this project/whatever copyright holder -->\n", 1900 + tm->tm_year);
fprintf(f, " <link href=\"https://example.com\" />\n");
fprintf(f, " </copyright>\n");
fprintf(f, " <footer>\n");
fprintf(f, " <p>This part is shared between files!</p>\n");
fprintf(f, " </footer>\n");
fprintf(f, "</skinconfig>\n");
fclose(f);

View file

@ -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, " <div id=\"footer\">\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, " <a href=\"https://validator.w3.org/check/referer\"><img src=\"%simage/valid-html401.png\" alt=\"Valid HTML 4.01\" border=\"0\" width=\"88\" height=\"31\"></a>\n", top);
fprintf(out, " <a href=\"https://jigsaw.w3.org/css-validator/\"><img src=\"%simage/valid-css.png\" alt=\"Valid CSS\" border=\"0\" width=\"88\" height=\"31\"></a>\n", top);
fprintf(out, " <p id=\"copyright\">\n");

View file

@ -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;

View file

@ -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