all repos — eureka @ 10d57d0f6cd9a7c702680dcfebaf1ed9eba889e8

static site generator based on the 100r.co engine

update edit time logic in footer
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmNUyoMACgkQO3+8IhRO
Y5jyYw//diUebkrHHWTYfA2IjhQyJDz8/tgc3M7e3MWMSweNSu6Vkvobeqi+lLud
ZgNwXht2L6T3AFmL6+3v2BHrFkKNsYqSu8ksamyK/3QEee8WzNxleieMe0O+fRwk
ESywUWzv0NjziP0pJc4sPn8vQGo9jr+2NHhGnEwBRzX2FEGyWKYDR/eLEKgKpi/D
0UhOqGsrEJSq6HgACobXi4AlsGEYChLs1tox2dRqP2n8p7AFXR/wBZyvxpwTv1M2
5QymRjDNTWYguyKD9EBFCe5J5+LIU5e3B+uYg9agG+G4jPcfu8F3p1U8F9VnNMq3
pVQjALuOuTVPBUaf4ZajUKz97FZ/VvQ64wVDjMecXTKd30vtj5KPGJtlKtSp7B5o
I6jHjLzPwVeMJ6yhfonEPP6IXOuFCwM/lqjfJ1u6Yum2t1+FHmdZbNtY3gO4WAA6
rJcpj/l4wpINAt1f118bd+i4EVRBQwegyDFPkj8bf06FzlehXf6YLjdyoWmXUQYn
2Oc1K2pi3i+qNo3QYd8mXBAZjf672DZYmc/MhuQEZ3huI4yJp+wKdUhjdQaC+fPv
3Nyr/AWXRrsdn0ZOfM4FnWn5saH3HMUd5CbeM/6UJlvO2kyCrViEbe/A9j8FD/Y1
l/4i36eyhHbbaWb+P1c/3U7TvSiUB0Z0r9PBPy97z/yufqBIuLk=
=PYpZ
-----END PGP SIGNATURE-----
commit

10d57d0f6cd9a7c702680dcfebaf1ed9eba889e8

parent

3d8711dc38f0fff0c2292b346d2f590c45f82a0b

1 files changed, 37 insertions(+), 14 deletions(-)

jump to
M main.cmain.c

@@ -21,6 +21,7 @@ WITH REGARD TO THIS SOFTWARE.

*/ struct dirent* dir; +time_t edittime; typedef struct Lexicon { int len, refs[LEXICON_SIZE];

@@ -50,6 +51,8 @@ int error(char* msg, char* val) {

printf("Error: %s(%s)\n", msg, val); return 0; } + +time_t getlater(time_t a, time_t b) { return a > b ? a : b; } int ismetanav(char* name) { return scmp(name, "meta.nav"); }

@@ -109,13 +112,18 @@ return 1;

} } -void fpedited(FILE* f, char* path) { - struct stat attr; - stat(path, &attr); - fprintf(f, "Edited on %s<br/>", ctime(&attr.st_mtime)); +void fpedited(FILE* f) { + struct tm timebuf; + char strbuf[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + + timebuf = *localtime(&edittime); + strftime(strbuf, 16, "%Y-%m-%d", &timebuf); + + fprintf(f, "modified %s<br/>", strbuf); } int fpportal(FILE* f, Lexicon* l, char* s, int head) { + struct stat attr; int target; char srcpath[64], filename[64]; target = findf(l, s);

@@ -124,6 +132,10 @@ return error("Missing portal", s);

srcpath[0] = 0; filename[0] = 0; scat(scat(scat(srcpath, "inc/"), scpy(s, filename, 64)), ".htm"); + stat(scsw(srcpath, ' ', '_'), &attr); + if (!ismetanav(s)) { + edittime = getlater(edittime, attr.st_mtime); + } if (head) fprintf( f,

@@ -454,10 +466,12 @@ return fpli(f, l, s + 1);

case '&': return fppara(f, l, s + 1); } - if (s[0]) + if (s[0]) { target = findf(l, s); - if (target < 0) + } + if (target < 0) { return error("Missing link", s); + } fprintf(f, "<a href='./%s.html' class='local'>", scsw(stlc(s), ' ', '_')); fprintf(f, "%s</a>", scsw(stlc(s), '_', ' ')); l->refs[target]++;

@@ -498,8 +512,9 @@ if (slen(s) >= TAG_BODY_SIZE)

return error("Templating error", "text block exceeds tag body size"); if (t) { ccat(ss, *s); - } else + } else { fprintf(f, "%c", *s); + } s++; } return 1;

@@ -516,6 +531,7 @@ bclose = 0;

scsw(filepath, ' ', '_'); if (!(inc = fopen(filepath, "r"))) return error("Missing include", filepath); + s[0] = 0; while ((c = fgetc(inc)) != EOF) { if (c == '}') {

@@ -538,23 +554,26 @@ t = 1;

continue; } } - if (slen(s) >= TAG_BODY_SIZE) + if (slen(s) >= TAG_BODY_SIZE) { return error("Templating error", filepath); - if (t) + } + if (t) { ccat(s, c); - else + } else { fprintf(f, "%c", c); + } } fclose(inc); return 1; } -int fpfooter(FILE* f, char* name, char* path) { - if (!f || !name || !path) +int fpfooter(FILE* f, char* name) { + if (!f || !name) { return 0; + } fputs("<footer>", f); if (!ismetanav(name)) { - fpedited(f, path); + fpedited(f); fputs(CONTACT, f); } fputs(FOOTER, f);

@@ -564,9 +583,11 @@ return 1;

} FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) { + struct stat attr; if (!f) return f; /* begin */ + fputs("<!DOCTYPE html>\n<html lang='en'>\n", f); fputs("<head>\n", f); fprintf(

@@ -606,6 +627,8 @@ if (!fpportal(f, l, "meta.nav", 0))

printf(">>> Building failed: %s\n", name); fputs("</nav>\n", f); /* main */ + stat(srcpath, &attr); + edittime = attr.st_mtime; if (!ismetanav(name)) { fputs("<main>\n", f); fprintf(f, "<h2>%s</h2>\n", name);

@@ -616,7 +639,7 @@ } else {

gettwtxt(f); } /* footer */ - if (!fpfooter(f, name, srcpath)) { + if (!fpfooter(f, name)) { printf(">>> Building failed: footer(%s)\n", name); }