update edit time logic in footer
This commit is contained in:
parent
3d8711dc38
commit
10d57d0f6c
1 changed files with 37 additions and 14 deletions
51
main.c
51
main.c
|
@ -21,6 +21,7 @@ WITH REGARD TO THIS SOFTWARE.
|
|||
*/
|
||||
|
||||
struct dirent* dir;
|
||||
time_t edittime;
|
||||
|
||||
typedef struct Lexicon {
|
||||
int len, refs[LEXICON_SIZE];
|
||||
|
@ -51,6 +52,8 @@ int error(char* msg, char* 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"); }
|
||||
|
||||
int findf(Lexicon* l, char* f) {
|
||||
|
@ -109,13 +112,18 @@ int gettwtxt(FILE* f) {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ int fpportal(FILE* f, Lexicon* l, char* s, int head) {
|
|||
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 @@ int fptemplate(FILE* f, Lexicon* l, char* s) {
|
|||
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 @@ int fpmetatemplate(FILE* f, Lexicon* l, char* s) {
|
|||
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 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) {
|
|||
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 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) {
|
|||
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 @@ int fpfooter(FILE* f, char* name, char* path) {
|
|||
}
|
||||
|
||||
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 @@ FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) {
|
|||
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 @@ FILE* build(FILE* f, Lexicon* l, char* name, char* srcpath) {
|
|||
gettwtxt(f);
|
||||
}
|
||||
/* footer */
|
||||
if (!fpfooter(f, name, srcpath)) {
|
||||
if (!fpfooter(f, name)) {
|
||||
printf(">>> Building failed: footer(%s)\n", name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue