saait

Simple static page generator
git clone https://git.sinitax.com/codemadness/saait
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 8c2dd34a14080ceffe4250502707237cabc9ac26
parent 8c39944139de302656b2e5c075dbd934a1a51a1f
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 25 Nov 2016 16:27:12 +0100

add readfile op

Diffstat:
MREADME | 16+++++++++++++++-
MTODO | 41+++++------------------------------------
Msaait.c | 33++++++++++++++++++++-------------
Mtemplates/atom.xml/item.xml | 4++--
Mtemplates/index.html/item.html | 2+-
Mtemplates/page/item.html | 2+-
Mtemplates/rss.xml/item.xml | 4++--
Mtemplates/sitemap.xml/item.xml | 2+-
Mtemplates/urllist.txt/item.txt | 2+-
9 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/README b/README @@ -7,7 +7,10 @@ Some parts are intentionally hardcoded, C knowledge is required. Dependencies: - requires non-standard field tm_gmtoff in struct tm. +------------- +- C compiler +- libc +- requires non-standard field tm_gmtoff in struct tm. Directory structure for pages: @@ -26,6 +29,9 @@ The files are saved as output/<templatename>.ext the templatename "page" is special and will be used per page. +otherwise the directory name is used as the output file, for example +templates/atom.xml/templatefiles* will be: output/atom.xml + Cfg file: @@ -34,6 +40,8 @@ variables set by program: TODO: basefile +file (if not already set) +filename url urlfull / urlabsolute / absoluteurl datecreated @@ -62,3 +70,9 @@ created_rss and updated_rss RSS date Variables: ${} escaped HTML/XML string. #{} literal string. +%{} insert contents of file of variable value. + +Date format: +${value@date format} +#{value@date format} +%{value@date format} diff --git a/TODO b/TODO @@ -1,30 +1,4 @@ -x RSS time is in GMT... - - -parse time (localtime vs gmtime?). - TODO: read times specified without timezone as localtime (not GMT). - TODO: when timezone is specified use it. - TODO: use strftime to show using timezone. - TODO: change siteupdated atom/rss format (don't hardcode GMT). - - -write alot better documentation. - -make time variable special? something like (syntax should change): - - -? read file and output data. -%{"filename"} - -? execute and insert output:: -!{"command"} - -x interpret a few formats: -%Y-%m-%d %H:%M:%S -%Y-%m-%d %H:%M -%Y-%m-%dT%H:%M:%SZ -%Y-%m-%dT%H:%M:%S - +improve documentation make template structure: @@ -43,12 +17,7 @@ must work on: Linux, OpenBSD, MingW (Windows). OpenBSD libc -cfg: date timezone: created, updated - - -set builddate as variable to use. -set RFC and standard date as variable to use. - -show line number in error -max 500 LOC -pledge +- show line number in error + improve +- max 1000 LOC +x pledge diff --git a/saait.c b/saait.c @@ -472,6 +472,7 @@ writepage(FILE *fp, const char *filename, struct config *c, char *s) /* TODO: revert static key size */ char key[64], escape, *e, *value; size_t keylen, line = 0; + int op; char *tmp; /* TODO */ /* TODO */ @@ -481,10 +482,11 @@ writepage(FILE *fp, const char *filename, struct config *c, char *s) for (; *s; s++) { /* TODO: error if unterminated */ - - switch (*s) { - case '#': - case '$': + op = *s; + switch (op) { + case '%': /* insert contents of filename set in variable */ + case '#': /* insert value non-escaped */ + case '$': /* insert value escaped */ escape = (*s == '$'); if (*(s + 1) == '{') { s += 2; @@ -538,11 +540,14 @@ writepage(FILE *fp, const char *filename, struct config *c, char *s) } value = v->value; + if (op == '%') + value = readfile(value); + + /* format date */ if (*s == '@') { for (e = ++s; *e && *e != '}'; e++) ; - /* TODO: check with different input timezones */ parsetime(v->value, &t, &tm, NULL); /* TODO: check */ @@ -561,6 +566,9 @@ writepage(FILE *fp, const char *filename, struct config *c, char *s) xmlencode(value, fp); else fputs(value, fp); + + if (op == '%') + free(value); } } @@ -581,7 +589,7 @@ main(int argc, char *argv[]) struct config *c; DIR *dirp, *dirt; struct dirent *dp, *dt; - char *p, *content, *base, *basefile, file[PATH_MAX], dir[PATH_MAX]; + char *p, *base, *basefile, file[PATH_MAX], dir[PATH_MAX]; char outputfile[PATH_MAX]; int i, r; @@ -689,17 +697,16 @@ main(int argc, char *argv[]) fprintf(stderr, "path truncated: '%s'\n", argv[i]); exit(1); } - content = readfile(file); + + /* set file if not set */ + if (!getvar(c->vars, "file")) + setvar(&c->vars, newvar("file", file)); /* set HTML filename */ if ((p = strrchr(file, '/'))) - setvar(&c->vars, newvar("file", &file[p - file + 1])); + setvar(&c->vars, newvar("filename", &file[p - file + 1])); else - setvar(&c->vars, newvar("file", file)); - - /* set content */ - setvar(&c->vars, newvar("content", content)); - free(content); + setvar(&c->vars, newvar("filename", file)); for (t = templates; t; t = t->next) { /* TODO: page is a special case for now */ diff --git a/templates/atom.xml/item.xml b/templates/atom.xml/item.xml @@ -1,7 +1,7 @@ <entry> <title type="html">${title}</title> - <link rel="alternate" type="text/html" href="${siteurl}/${file}" /> - <id>${siteurl}/${file}</id> + <link rel="alternate" type="text/html" href="${siteurl}/${filename}" /> + <id>${siteurl}/${filename}</id> <updated>${updated@%Y-%m-%dT%H:%M:%S%z}</updated> <published>${created@%Y-%m-%dT%H:%M:%S%z}</published> <author> diff --git a/templates/index.html/item.html b/templates/index.html/item.html @@ -1,4 +1,4 @@ <tr> <td>${updated@%Y-%m-%d}</td> - <td><a href="${file}" title="${description}">${title}</a></td> + <td><a href="${filename}" title="${description}">${title}</a></td> </tr> diff --git a/templates/page/item.html b/templates/page/item.html @@ -1,3 +1,3 @@ <h1><a href="">${title}</a></h1> <em><strong>Written:</strong> ${created@%Y-%m-%d}</em> - #{content} + %{file} diff --git a/templates/rss.xml/item.xml b/templates/rss.xml/item.xml @@ -1,8 +1,8 @@ <item> <title>${title}</title> - <link>${siteurl}/${file}</link> + <link>${siteurl}/${filename}</link> <pubDate>${updated@%a, %d %b %Y %H:%M:%S %z}</pubDate> <author>${author}</author> - <guid isPermaLink="false">${siteurl}/${file}</guid> + <guid isPermaLink="false">${siteurl}/${filename}</guid> <description><![CDATA[${description}]]></description> </item> diff --git a/templates/sitemap.xml/item.xml b/templates/sitemap.xml/item.xml @@ -1 +1 @@ -<url><loc>${siteurl}/${file}</loc></url> +<url><loc>${siteurl}/${filename}</loc></url> diff --git a/templates/urllist.txt/item.txt b/templates/urllist.txt/item.txt @@ -1 +1 @@ -${siteurl}/${file} +${siteurl}/${filename}