update edit time logic in footer

This commit is contained in:
Iris Lightshard 2022-10-22 23:00:51 -06:00
parent 3d8711dc38
commit 10d57d0f6c
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398

51
main.c
View file

@ -21,6 +21,7 @@ WITH REGARD TO THIS SOFTWARE.
*/ */
struct dirent* dir; struct dirent* dir;
time_t edittime;
typedef struct Lexicon { typedef struct Lexicon {
int len, refs[LEXICON_SIZE]; int len, refs[LEXICON_SIZE];
@ -51,6 +52,8 @@ int error(char* msg, char* val) {
return 0; 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"); } int ismetanav(char* name) { return scmp(name, "meta.nav"); }
int findf(Lexicon* l, char* f) { int findf(Lexicon* l, char* f) {
@ -109,13 +112,18 @@ int gettwtxt(FILE* f) {
} }
} }
void fpedited(FILE* f, char* path) { void fpedited(FILE* f) {
struct stat attr; struct tm timebuf;
stat(path, &attr); char strbuf[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
fprintf(f, "Edited on %s<br/>", ctime(&attr.st_mtime));
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) { int fpportal(FILE* f, Lexicon* l, char* s, int head) {
struct stat attr;
int target; int target;
char srcpath[64], filename[64]; char srcpath[64], filename[64];
target = findf(l, s); target = findf(l, s);
@ -124,6 +132,10 @@ int fpportal(FILE* f, Lexicon* l, char* s, int head) {
srcpath[0] = 0; srcpath[0] = 0;
filename[0] = 0; filename[0] = 0;
scat(scat(scat(srcpath, "inc/"), scpy(s, filename, 64)), ".htm"); 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) if (head)
fprintf( fprintf(
f, f,
@ -454,10 +466,12 @@ int fptemplate(FILE* f, Lexicon* l, char* s) {
case '&': case '&':
return fppara(f, l, s + 1); return fppara(f, l, s + 1);
} }
if (s[0]) if (s[0]) {
target = findf(l, s); target = findf(l, s);
if (target < 0) }
if (target < 0) {
return error("Missing link", s); return error("Missing link", s);
}
fprintf(f, "<a href='./%s.html' class='local'>", scsw(stlc(s), ' ', '_')); fprintf(f, "<a href='./%s.html' class='local'>", scsw(stlc(s), ' ', '_'));
fprintf(f, "%s</a>", scsw(stlc(s), '_', ' ')); fprintf(f, "%s</a>", scsw(stlc(s), '_', ' '));
l->refs[target]++; l->refs[target]++;
@ -498,8 +512,9 @@ int fpmetatemplate(FILE* f, Lexicon* l, char* s) {
return error("Templating error", "text block exceeds tag body size"); return error("Templating error", "text block exceeds tag body size");
if (t) { if (t) {
ccat(ss, *s); ccat(ss, *s);
} else } else {
fprintf(f, "%c", *s); fprintf(f, "%c", *s);
}
s++; s++;
} }
return 1; return 1;
@ -516,6 +531,7 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) {
scsw(filepath, ' ', '_'); scsw(filepath, ' ', '_');
if (!(inc = fopen(filepath, "r"))) if (!(inc = fopen(filepath, "r")))
return error("Missing include", filepath); return error("Missing include", filepath);
s[0] = 0; s[0] = 0;
while ((c = fgetc(inc)) != EOF) { while ((c = fgetc(inc)) != EOF) {
if (c == '}') { if (c == '}') {
@ -538,23 +554,26 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) {
continue; continue;
} }
} }
if (slen(s) >= TAG_BODY_SIZE) if (slen(s) >= TAG_BODY_SIZE) {
return error("Templating error", filepath); return error("Templating error", filepath);
if (t) }
if (t) {
ccat(s, c); ccat(s, c);
else } else {
fprintf(f, "%c", c); fprintf(f, "%c", c);
} }
}
fclose(inc); fclose(inc);
return 1; return 1;
} }
int fpfooter(FILE* f, char* name, char* path) { int fpfooter(FILE* f, char* name) {
if (!f || !name || !path) if (!f || !name) {
return 0; return 0;
}
fputs("<footer>", f); fputs("<footer>", f);
if (!ismetanav(name)) { if (!ismetanav(name)) {
fpedited(f, path); fpedited(f);
fputs(CONTACT, f); fputs(CONTACT, f);
} }
fputs(FOOTER, f); fputs(FOOTER, f);
@ -564,9 +583,11 @@ int fpfooter(FILE* f, char* name, char* path) {
} }
FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) { FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) {
struct stat attr;
if (!f) if (!f)
return f; return f;
/* begin */ /* begin */
fputs("<!DOCTYPE html>\n<html lang='en'>\n", f); fputs("<!DOCTYPE html>\n<html lang='en'>\n", f);
fputs("<head>\n", f); fputs("<head>\n", f);
fprintf( fprintf(
@ -606,6 +627,8 @@ FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) {
printf(">>> Building failed: %s\n", name); printf(">>> Building failed: %s\n", name);
fputs("</nav>\n", f); fputs("</nav>\n", f);
/* main */ /* main */
stat(srcpath, &attr);
edittime = attr.st_mtime;
if (!ismetanav(name)) { if (!ismetanav(name)) {
fputs("<main>\n", f); fputs("<main>\n", f);
fprintf(f, "<h2>%s</h2>\n", name); fprintf(f, "<h2>%s</h2>\n", name);
@ -616,7 +639,7 @@ FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) {
gettwtxt(f); gettwtxt(f);
} }
/* footer */ /* footer */
if (!fpfooter(f, name, srcpath)) { if (!fpfooter(f, name)) {
printf(">>> Building failed: footer(%s)\n", name); printf(">>> Building failed: footer(%s)\n", name);
} }