about summary refs log tree commit diff
path: root/atom.c
diff options
context:
space:
mode:
Diffstat (limited to 'atom.c')
-rw-r--r--atom.c32
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);
 }