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

This commit is contained in:
Nishi 2026-03-03 01:31:01 +09:00
commit 2bddddeca1
Signed by: nishi
GPG key ID: 27EF69B208EB9343
5 changed files with 104 additions and 8 deletions

View file

@ -111,7 +111,16 @@ 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);
child = header->first_child;
while(child != NULL) {
default_head(out, top, child, 2);
child = child->next;
}
}
void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body) {
@ -181,6 +190,8 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body
}
if(link == NULL) link = "https://invalid.link";
link = u_path(top, link);
sprintf(path, "%s.image", images[i]);
if((nodes = xl_get_path(skinconf->root, path)) != NULL) {
char* text = xl_get_attribute(nodes[0], "src");
@ -193,6 +204,8 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body
free(nodes);
}
free(link);
}
fprintf(out, " </td>\n");
fprintf(out, " </tr>\n");
@ -208,10 +221,15 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body
char* name = xl_get_attribute(nodes[i], "name");
if(link == NULL) link = "https://invalid.link";
link = u_path(top, link);
if(title == NULL) title = link;
if(i > 0) fprintf(out, " |\n");
fprintf(out, " <a href=\"%s\">%s</a>\n", link, name);
free(link);
}
free(nodes);
@ -252,7 +270,7 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body
child = body->first_child;
while(child != NULL) {
default_node(out, top, child, 6);
default_body(out, top, child, 6);
child = child->next;
}

View file

@ -38,7 +38,44 @@ static void accept_attr(char* text, xl_node_t* element, ...) {
}
}
void default_node(FILE* out, const char* top, xl_node_t* element, int indent) {
void default_head(FILE* out, const char* top, xl_node_t* element, int indent) {
xl_node_t* child;
char tag[2048];
char end[128];
int add = 0;
tag[0] = end[0] = 0;
if(element->name == NULL) return;
if(strcmp(element->name, "link") == 0) {
char text[2048];
accept_attr(text, element, "rel", "href", NULL);
sprintf(tag, "<%s%s>", element->name, text);
}
if(tag[0] != 0) print(out, tag, indent);
child = element->first_child;
while(child != NULL) {
if(child->type == XL_NODE_NODE && child->name != NULL) {
default_head(out, top, child, indent + 1 + add);
} else if(child->type == XL_NODE_TEXT && child->text != NULL) {
/* most likely junk */
#if 0
print(out, child->text, indent + 1 + add);
#endif
}
child = child->next;
}
if(end[0] != 0) print(out, end, indent);
}
void default_body(FILE* out, const char* top, xl_node_t* element, int indent) {
xl_node_t* child;
char tag[2048]; /* enough for most cases... :) */
char end[128];
@ -137,7 +174,7 @@ void default_node(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_node(out, top, child, indent + 1 + add);
default_body(out, top, child, indent + 1 + add);
} else if(child->type == XL_NODE_TEXT && child->text != NULL) {
print(out, child->text, indent + 1 + add);
}
@ -160,8 +197,12 @@ void default_nav(FILE* out, const char* top, xl_node_t* element, int indent) {
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");
fprintf(out, " - <a href=\"%s\">%s</a><br>\n", link, name);
free(link);
} else if(strcmp(element->name, "group") == 0) {
char* title;
xl_node_t* child;

View file

@ -15,10 +15,13 @@ static int parse_file(const char* top, const char* full) {
}
if(st) {
char* title = NULL;
xl_node_t* node = NULL;
xl_node_t* header = NULL;
xl_node_t* body = NULL;
char* title = NULL;
xl_node_t* node = NULL;
xl_node_t* header = NULL;
xl_node_t* body = NULL;
xl_node_t** nodes;
xl_node_t** nodes2;
int has_own_icon = 0;
if(handle->root != NULL) node = handle->root->first_child;
while(node != NULL) {
@ -48,7 +51,34 @@ static int parse_file(const char* top, const char* full) {
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);
if((nodes = xl_get_path(header, "link")) != NULL) {
int i;
for(i = 0; nodes[i] != NULL; i++) {
char* rel = xl_get_attribute(nodes[i], "rel");
if(strcmp(rel, "icon") == 0) {
has_own_icon = 1;
break;
}
}
free(nodes);
}
classic_head(f, top, header);
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);
free(p);
}
free(nodes);
}
fprintf(f, " </head>\n");
fprintf(f, " <body>\n");
classic_body(f, top, title, body);

View file

@ -48,6 +48,11 @@ int action_seed(int argc, char** argv) {
return 1;
}
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, "-->\n");
fprintf(f, "<skinconfig>\n");
fprintf(f, " <search domain=\"example.com\" />\n");
fprintf(f, " <breadcrumb>\n");
@ -76,6 +81,7 @@ int action_seed(int argc, char** argv) {
fprintf(f, " </group>\n");
fprintf(f, " </group>\n");
fprintf(f, " </nav>\n");
fprintf(f, " <favicon></favicon>\n");
fprintf(f, " <copyright>\n");
fprintf(f, " <holder>Example Co, Ltd</holder>\n");
fprintf(f, " <year>2026</year>\n");

View file

@ -72,7 +72,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);
/* default.c */
void default_node(FILE* out, const char* top, xl_node_t* element, int indent);
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