saait

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

commit 081c3fb57aaf2dd6b6019bc6b270511fa821d1ae
parent 79f542131b02995e4bb1ba36e0f67b38c8551a35
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 16 Feb 2020 17:59:02 +0100

rename htmlfile to contentfile, reword some things in docs

saait is intended for site generator, can be used for other text templates,
like Atom feeds, etc.

Diffstat:
Msaait.1 | 26++++++++++++++++----------
Msaait.c | 31++++++++++++++++---------------
Mtemplates/page/item.html | 2+-
3 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/saait.1 b/saait.1 @@ -77,21 +77,27 @@ updated = 2009-04-14 .Pp The following variables names are special with their respective default values: .Bl -tag -width Ds +.It contentfile +Path to the input content filename, by default this is the path of +the config file with the last extension replaced to ".html". .It filename -The relative file path of the output HTML file for this page. -The path is relative to the -.Ar outputdir . -.It htmlfile -Path to the input HTML content filename, by default this is the path of -the config file with the last extension replaced to .html. +The filename or relative file path for the output file for this page. +By default the value is the basename of the +.Va contentfile . +The path of the written output file is the value of +.Va filename +appended to the +.Ar outputdir +path. .El .Pp -A line starting with # is ignored and can be used as a comment. +A line starting with # is a comment and is ignored. .Pp TABs and spaces before and after a variable name are ignored. TABs and spaces before a value are ignored. -.Sh TEMPLATE SYNTAX -The variables set in a config file can be used inside templates, but not pages. +.Sh TEMPLATES +A template (block) is text. +Variables are replaced with the values set in the config files. .Pp The possible operators for variables are: .Bl -tag -width Ds @@ -113,7 +119,7 @@ For example in a HTML item template: <time datetime="${updated}">${updated}</time> </p> </header> - %{htmlfile} + %{contentfile} </article> .Ed .Sh EXIT STATUS diff --git a/saait.c b/saait.c @@ -405,7 +405,7 @@ main(int argc, char *argv[]) struct variable *c, *v; DIR *bdir, *idir; struct dirent be, ie, *br, *ir; - char file[PATH_MAX + 1], htmlfile[PATH_MAX + 1], path[PATH_MAX + 1]; + char file[PATH_MAX + 1], contentfile[PATH_MAX + 1], path[PATH_MAX + 1]; char outputfile[PATH_MAX + 1], *p, *filename; size_t i, j, k, templateslen; int argi, r; @@ -515,28 +515,29 @@ main(int argc, char *argv[]) c = readconfig(argv[i]); if ((p = strrchr(argv[i], '.'))) - r = snprintf(htmlfile, sizeof(htmlfile), "%.*s.html", + r = snprintf(contentfile, sizeof(contentfile), "%.*s.html", (int)(p - argv[i]), argv[i]); else - r = snprintf(htmlfile, sizeof(htmlfile), "%s.html", argv[i]); - if (r < 0 || (size_t)r >= sizeof(htmlfile)) { + r = snprintf(contentfile, sizeof(contentfile), "%s.html", argv[i]); + if (r < 0 || (size_t)r >= sizeof(contentfile)) { fprintf(stderr, "path truncated for file: '%s'\n", argv[i]); exit(1); } - /* set htmlfile, but allow to override it */ - setvar(&c, newvar("htmlfile", htmlfile), 0); + /* set contentfile, but allow to override it */ + setvar(&c, newvar("contentfile", contentfile), 0); - /* set HTML output filename (with part removed), but allow to - override it */ - if ((p = strrchr(htmlfile, '/'))) - filename = &htmlfile[p - htmlfile + 1]; - else - filename = htmlfile; - - if ((v = getvar(c, "filename"))) + if ((v = getvar(c, "filename"))) { filename = v->value; - else + } else { + /* set output filename (with path removed), but allow + to override it */ + if ((p = strrchr(contentfile, '/'))) + filename = &contentfile[p - contentfile + 1]; + else + filename = contentfile; + setvar(&c, newvar("filename", filename), 0); + } /* item blocks */ for (j = 0; j < templateslen; j++) { diff --git a/templates/page/item.html b/templates/page/item.html @@ -3,4 +3,4 @@ <p><strong>Last modification on </strong> <time datetime="${updated}">${updated}</time></p> </header> -%{htmlfile} +%{contentfile}