This commit is contained in:
parent
583bf73c4d
commit
3d0d4ca891
8 changed files with 120 additions and 3 deletions
3
objs.mk
3
objs.mk
|
|
@ -17,6 +17,9 @@ src/external_xemil_src_util.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_crc.o
|
||||
src/src_crc.o: src/crc.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/crc.c
|
||||
OBJS += src/src_default.o
|
||||
src/src_default.o: src/default.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/default.c
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ void classic_stylesheet(FILE* out, const char* top) {
|
|||
fprintf(out, " padding: 8px;\n");
|
||||
fprintf(out, "}\n");
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, "#footer {\n");
|
||||
fprintf(out, " padding-top: 0;\n");
|
||||
fprintf(out, "}\n");
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, ".section {\n");
|
||||
fprintf(out, " background-color: #eeeeee;\n");
|
||||
fprintf(out, " padding-left: 8px;\n");
|
||||
|
|
@ -278,6 +282,27 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body
|
|||
fprintf(out, " <td width=\"150\" valign=\"top\">\n");
|
||||
fprintf(out, " <div id=\"nav\">\n");
|
||||
|
||||
if((nodes = xl_get_path(body, "section")) != NULL) {
|
||||
int i;
|
||||
|
||||
fprintf(out, " <div class=\"linkgrouptitle\"> - Contents</div>\n");
|
||||
fprintf(out, " <div class=\"linkgroup\">\n");
|
||||
|
||||
for(i = 0; nodes[i] != NULL; i++) {
|
||||
char* name = NULL;
|
||||
char* id;
|
||||
|
||||
if((name = xl_get_attribute(nodes[i], "title")) == NULL) continue;
|
||||
|
||||
id = u_section_id(nodes[i]);
|
||||
|
||||
fprintf(out, " - <a href=\"#%s\">%s</a><br>\n", id, name);
|
||||
}
|
||||
|
||||
fprintf(out, " </div>\n");
|
||||
fprintf(out, " <br>\n");
|
||||
}
|
||||
|
||||
if((nodes = xl_get_path(skinconf->root, "nav")) != NULL) {
|
||||
int i;
|
||||
|
||||
|
|
|
|||
25
src/crc.c
Normal file
25
src/crc.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* crc32.c -- compute the CRC-32 of a data stream
|
||||
* Copyright (C) 1995-1998 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include <taiga.h>
|
||||
|
||||
unsigned int crc32(void* input, unsigned int len) {
|
||||
int i, j;
|
||||
unsigned int byte, crc, mask;
|
||||
unsigned char* message = input;
|
||||
|
||||
i = 0;
|
||||
crc = 0xFFFFFFFF;
|
||||
while(i < len) {
|
||||
byte = message[i]; // Get next byte.
|
||||
crc = crc ^ byte;
|
||||
for(j = 7; j >= 0; j--) { // Do eight times.
|
||||
mask = -(crc & 1);
|
||||
crc = (crc >> 1) ^ (0xEDB88320 & mask);
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
|
@ -103,8 +103,9 @@ void default_body(FILE* out, const char* top, xl_node_t* element, int spec, int
|
|||
|
||||
if(strcmp(element->name, "section") == 0) {
|
||||
char* title = xl_get_attribute(element, "title");
|
||||
char* id = u_section_id(element);
|
||||
|
||||
sprintf(tag, "<div class=\"section\">%s</div>", title);
|
||||
if(id != NULL) sprintf(tag, "<div class=\"section\" id=\"%s\">%s</div>", id, title);
|
||||
} else if(strcmp(element->name, "fixme") == 0 || /**/
|
||||
strcmp(element->name, "warning") == 0 || /**/
|
||||
strcmp(element->name, "note") == 0) {
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ int action_seed(int argc, char** argv) {
|
|||
fprintf(f, " <td>Test</td>\n");
|
||||
fprintf(f, " </tr>\n");
|
||||
fprintf(f, " </table>\n");
|
||||
fprintf(f, " <section title=\"Congratulations\">\n");
|
||||
fprintf(f, " <section id=\"congrats\" 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");
|
||||
|
|
|
|||
35
src/simple.c
35
src/simple.c
|
|
@ -156,7 +156,6 @@ void simple_stylesheet(FILE* out, const char* top) {
|
|||
fprintf(out, "\n");
|
||||
fprintf(out, ".message-icon {\n");
|
||||
fprintf(out, " padding-right: 5px;\n");
|
||||
;
|
||||
fprintf(out, "}\n");
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, ".message-title {\n");
|
||||
|
|
@ -168,6 +167,14 @@ void simple_stylesheet(FILE* out, const char* top) {
|
|||
fprintf(out, " border-bottom: solid 1px #808080;\n");
|
||||
fprintf(out, "}\n");
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, ".box-content ul {\n");
|
||||
fprintf(out, " margin: 0;\n");
|
||||
fprintf(out, " padding-top: 8px;\n");
|
||||
fprintf(out, " padding-bottom: 8px;\n");
|
||||
fprintf(out, " padding-left: 28px;\n");
|
||||
fprintf(out, " padding-right: 18px;\n");
|
||||
fprintf(out, "}\n");
|
||||
fprintf(out, "\n");
|
||||
|
||||
for(i = 0; i < sizeof(messages) / sizeof(messages[0]); i++) {
|
||||
fprintf(out, ".%s-message {\n", messages[i]);
|
||||
|
|
@ -281,6 +288,32 @@ void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body)
|
|||
fprintf(out, " </tr>\n");
|
||||
fprintf(out, " <tr>\n");
|
||||
fprintf(out, " <td id=\"nav\" valign=\"top\">\n");
|
||||
|
||||
if((nodes = xl_get_path(body, "section")) != NULL) {
|
||||
int i;
|
||||
|
||||
fprintf(out, " <div class=\"box\">\n");
|
||||
fprintf(out, " <h2>CONTENTS</h2>\n");
|
||||
fprintf(out, " <div class=\"box-content\">\n");
|
||||
fprintf(out, " <ul>\n");
|
||||
|
||||
for(i = 0; nodes[i] != NULL; i++) {
|
||||
char* name = NULL;
|
||||
char* id;
|
||||
|
||||
if((name = xl_get_attribute(nodes[i], "title")) == NULL) continue;
|
||||
|
||||
id = u_section_id(nodes[i]);
|
||||
|
||||
fprintf(out, " <li><a href=\"#%s\">%s</a></li>\n", id, name);
|
||||
}
|
||||
|
||||
fprintf(out, " </ul>\n");
|
||||
fprintf(out, " </div>\n");
|
||||
fprintf(out, " </div>\n");
|
||||
free(nodes);
|
||||
}
|
||||
|
||||
fprintf(out, " <div class=\"box\">\n");
|
||||
fprintf(out, " <h2>LINKS</h2>\n");
|
||||
fprintf(out, " <div class=\"box-content\">\n");
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ char* u_strdup(const char* str);
|
|||
char* u_path(const char* top, const char* path);
|
||||
char* u_http_path(const char* top, const char* path);
|
||||
int u_image_size(const char* top, const char* path, char* (*path_func)(const char* top, const char* path), int* w, int* h);
|
||||
char* u_section_id(xl_node_t* node);
|
||||
|
||||
/* crc.c */
|
||||
unsigned int crc32(void* input, unsigned int len);
|
||||
|
||||
/* process.c */
|
||||
int process(const char* top, const char* out, const char* full);
|
||||
|
|
|
|||
26
src/util.c
26
src/util.c
|
|
@ -110,3 +110,29 @@ int u_image_size(const char* top, const char* path, char* (*path_func)(const cha
|
|||
|
||||
return st;
|
||||
}
|
||||
|
||||
char* u_section_id(xl_node_t* node) {
|
||||
char* name;
|
||||
char* id;
|
||||
|
||||
if((name = xl_get_attribute(node, "title")) == NULL) return NULL;
|
||||
|
||||
if((id = xl_get_attribute(node, "id")) != NULL) id = u_strdup(id);
|
||||
if(id == NULL) {
|
||||
int unique = 0;
|
||||
xl_node_t* child = node->parent->first_child;
|
||||
|
||||
while(child != NULL) {
|
||||
if(child == node) break;
|
||||
|
||||
unique++;
|
||||
child = child->next;
|
||||
}
|
||||
|
||||
id = malloc(64);
|
||||
|
||||
sprintf(id, "%d-%d", unique, crc32(name, strlen(name)));
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue