diff options
author | June McEnroe <june@causal.agency> | 2021-06-11 16:09:27 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-06-11 16:09:27 -0400 |
commit | 5956e421952721dfea0eff838f74a5d4f13b5e94 (patch) | |
tree | 9714a81ac8fdb2dcab2acaf54c1e3f3f29c8c47d /atom.c | |
parent | Ignore test directory (diff) | |
download | bubger-5956e421952721dfea0eff838f74a5d4f13b5e94.tar.gz bubger-5956e421952721dfea0eff838f74a5d4f13b5e94.zip |
Generalize index.{atom,html} to search pages
Diffstat (limited to '')
-rw-r--r-- | atom.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/atom.c b/atom.c index 14f9d54..a58f71c 100644 --- a/atom.c +++ b/atom.c @@ -28,6 +28,7 @@ #include <err.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sysexits.h> #include <time.h> @@ -162,26 +163,43 @@ int atomThreadClose(FILE *file) { return templateRender(file, Q(</feed>), NULL, NULL); } -int atomIndexOpen(FILE *file) { +static char *atomSearchURL(const char *name, const char *type) { + struct Variable vars[] = { + { "name", name }, + { "type", type }, + {0}, + }; + return templateString("/" PATH_SEARCH, vars, escapeURL); +} + +int atomSearchOpen(FILE *file, const char *name) { + char *atom = atomSearchURL(name, "atom"); + char *html = atomSearchURL(name, "html"); const char *template = XML_DECL Q( <feed xmlns="http://www.w3.org/2005/Atom"> <generator uri="[generator]">bubger</generator> - <id>[base]/</id> - <title>[title]</title> + <id>[base][atom]</id> + <title>[+name][name] - [-][title]</title> <updated>[updated]</updated> - <link rel="self" href="[base]/index.atom"/> - <link rel="alternate" type="text/html" href="[base]/index.html"/> + <link rel="self" href="[base][atom]"/> + <link rel="alternate" type="text/html" href="[base][html]"/> ); struct Variable vars[] = { { "generator", GENERATOR_URL }, + { "name", (strcmp(name, "index") ? name : NULL) }, { "title", baseTitle }, { "updated", iso8601(time(NULL)).s }, { "base", baseURL }, + { "atom", atom }, + { "html", html }, {0}, }; - return templateRender(file, template, vars, escapeXML); + int error = templateRender(file, template, vars, escapeXML); + free(atom); + free(html); + return error; } -int atomIndexClose(FILE *file) { +int atomSearchClose(FILE *file) { return templateRender(file, Q(</feed>), NULL, NULL); } |