diff options
Diffstat (limited to '')
-rw-r--r-- | html.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/html.c b/html.c index 5eb2f29..6b25996 100644 --- a/html.c +++ b/html.c @@ -545,12 +545,40 @@ int htmlSearchHead(FILE *file, const char *name) { return error; } -int htmlSearchOpen(FILE *file, const char *name) { +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); + 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); + 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"); 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> @@ -559,6 +587,8 @@ int htmlSearchOpen(FILE *file, const char *name) { <a href="mailto:[mailto]">write</a> [-] </nav> + ); + const char *tail = Q( </header> <main class="index"> <ol> @@ -566,12 +596,17 @@ int htmlSearchOpen(FILE *file, const char *name) { struct Variable vars[] = { { "name", (strcmp(name, "index") ? name : NULL) }, { "title", baseTitle }, + { "index", index }, { "atom", atom }, { "subscribe", baseSubscribe }, { "mailto", baseMailto }, {0}, }; - int error = templateRender(file, template, vars, escapeXML); + int error = 0 + || templateRender(file, template, vars, escapeXML) + || htmlSearchNav(file, name, searches, len) + || templateRender(file, tail, NULL, NULL); + free(index); free(atom); return error; } |