about summary refs log tree commit diff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'html.c')
-rw-r--r--html.c75
1 files changed, 40 insertions, 35 deletions
diff --git a/html.c b/html.c
index 6b25996..1dc531c 100644
--- a/html.c
+++ b/html.c
@@ -512,17 +512,17 @@ int htmlThreadClose(FILE *file) {
 		|| htmlFooter(file);
 }
 
-static char *htmlSearchURL(const char *name, const char *type) {
+static char *htmlIndexURL(const char *name, const char *type) {
 	struct Variable vars[] = {
 		{ "name", name },
 		{ "type", type },
 		{0},
 	};
-	return templateString(PATH_SEARCH, vars, escapeURL);
+	return templateString(PATH_INDEX, vars, escapeURL);
 }
 
-int htmlSearchHead(FILE *file, const char *name) {
-	char *atom = htmlSearchURL(name, "atom");
+int htmlIndexHead(FILE *file, const char *name) {
+	char *atom = htmlIndexURL(name, "atom");
 	const char *template = Q(
 		<!DOCTYPE html>
 		<meta charset="utf-8">
@@ -545,40 +545,47 @@ int htmlSearchHead(FILE *file, const char *name) {
 	return error;
 }
 
-static int htmlSearchNav(
-	FILE *file, const char *name, char *searches[const], size_t len
-) {
-	if (len < 2 || strcmp(name, "index")) return 0;
-	int error = templateRender(file, Q(<nav>), NULL, NULL);
+static int htmlSearchNavItem(FILE *file, const char *name, bool current) {
+	char *url = NULL;
+	const char *template;
+	if (current) {
+		template = Q(<b>[name]</b>) " ";
+	} else {
+		url = htmlIndexURL(name, "html");
+		template = Q(<a href="[url]">[name]</a>) " ";
+	}
+	struct Variable vars[] = {
+		{ "url", url },
+		{ "name", name },
+		{0},
+	};
+	int error = templateRender(file, template, vars, escapeXML);
+	free(url);
+	return error;
+}
+
+static int htmlSearchNav(FILE *file, const char *name) {
+	if (search.len < 2) return 0;
+	int error = 0
+		|| templateRender(file, Q(<nav>), NULL, NULL)
+		|| htmlSearchNavItem(file, "index", !strcmp(name, "index"));
 	if (error) return error;
-	for (size_t i = 0; i < len; ++i) {
-		if (!strcmp(searches[i], "index")) continue;
-		char *url = htmlSearchURL(searches[i], "html");
-		const char *template = Q(<a href="[url]">[search]</a>) " ";
-		struct Variable vars[] = {
-			{ "url", url },
-			{ "search", searches[i] },
-			{0},
-		};
-		error = templateRender(file, template, vars, escapeXML);
-		free(url);
+	for (size_t i = 0; i < search.len; ++i) {
+		if (!strcmp(search.names[i], "index")) continue;
+		error = htmlSearchNavItem(
+			file, search.names[i], !strcmp(search.names[i], name)
+		);
 		if (error) return error;
 	}
 	return templateRender(file, Q(</nav>), NULL, NULL);
 }
 
-int htmlSearchOpen(
-	FILE *file, const char *name, char *searches[const], size_t len
-) {
-	char *index = htmlSearchURL("index", "html");
-	char *atom = htmlSearchURL(name, "atom");
+int htmlIndexOpen(FILE *file, const char *name) {
+	char *atom = htmlIndexURL(name, "atom");
 	const char *template = Q(
 		<header class="index">
 			<h1>[+name][name] - [-][title]</h1>
 			<nav>
-				[+name]
-				<a href="[index]">index</a>
-				[-]
 				<a href="[atom]">follow</a>
 				[+subscribe]
 				<a href="[subscribe]">subscribe</a>
@@ -596,7 +603,6 @@ int htmlSearchOpen(
 	struct Variable vars[] = {
 		{ "name", (strcmp(name, "index") ? name : NULL) },
 		{ "title", baseTitle },
-		{ "index", index },
 		{ "atom", atom },
 		{ "subscribe", baseSubscribe },
 		{ "mailto", baseMailto },
@@ -604,14 +610,13 @@ int htmlSearchOpen(
 	};
 	int error = 0
 		|| templateRender(file, template, vars, escapeXML)
-		|| htmlSearchNav(file, name, searches, len)
+		|| htmlSearchNav(file, name)
 		|| templateRender(file, tail, NULL, NULL);
-	free(index);
 	free(atom);
 	return error;
 }
 
-static char *htmlSearchThreadURL(const struct Envelope *envelope) {
+static char *htmlIndexThreadURL(const struct Envelope *envelope) {
 	struct Variable vars[] = {
 		{ "messageID", envelope->messageID },
 		{ "type", "html" },
@@ -620,10 +625,10 @@ static char *htmlSearchThreadURL(const struct Envelope *envelope) {
 	return templateString(PATH_THREAD, vars, escapeURL);
 }
 
-int htmlSearchThread(
+int htmlIndexThread(
 	FILE *file, const struct Envelope *envelope, struct List thread
 ) {
-	char *url = htmlSearchThreadURL(envelope);
+	char *url = htmlIndexThreadURL(envelope);
 	const char *template = Q(
 		<li>
 			<h2 class="Subject"><a href="[url]">[subject]</a></h2>
@@ -648,7 +653,7 @@ int htmlSearchThread(
 	return error;
 }
 
-int htmlSearchClose(FILE *file) {
+int htmlIndexClose(FILE *file) {
 	return 0
 		|| templateRender(file, Q(</ol></main>), NULL, NULL)
 		|| htmlFooter(file);