diff options
Diffstat (limited to '')
-rw-r--r-- | html.c | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/html.c b/html.c index 3cc740c..24cdf1a 100644 --- a/html.c +++ b/html.c @@ -109,31 +109,31 @@ static char *htmlMbox(const char *messageID) { return templateURL("../" PATH_MESSAGE, vars); } +static int +htmlNavItem(FILE *file, const char *name, const char *base, const char *url) { + const char *template = TEMPLATE( + <li><a href="[base][url]">[name]</a></li> + ); + struct Variable vars[] = { + { "name", name }, + { "base", base }, + { "url", url }, + {0}, + }; + return templateRender(file, template, vars, escapeXML); +} + int htmlMessageNav(FILE *file, const struct Envelope *envelope) { int error = templateRender(file, TEMPLATE(<nav><ul>), NULL, NULL); if (error) return error; if (envelope->inReplyTo) { - const char *template = TEMPLATE( - <li><a href="[fragment]">parent</a></li> - ); char *fragment = htmlFragment(envelope->inReplyTo); - struct Variable vars[] = { - { "fragment", fragment }, - {0}, - }; - error = templateRender(file, template, vars, escapeXML); + error = htmlNavItem(file, "parent", "", fragment); free(fragment); if (error) return error; } - const char *template = TEMPLATE( - <li><a href="[mbox]">download</a></li> - ); char *mbox = htmlMbox(envelope->messageID); - struct Variable vars[] = { - { "mbox", mbox }, - {0}, - }; - error = templateRender(file, template, vars, escapeXML); + error = htmlNavItem(file, "download", "", mbox); free(mbox); if (error) return error; return templateRender(file, TEMPLATE(</ul></nav>), NULL, NULL); @@ -505,26 +505,38 @@ int htmlIndexHead(FILE *file) { return templateRender(file, template, vars, escapeXML); } +static int htmlIndexNav(FILE *file) { + int error = 0 + || templateRender(file, TEMPLATE(<nav><ul>), NULL, NULL) + || htmlNavItem(file, "follow", "", "index.atom"); + if (error) return error; + if (baseSubscribe) { + error = htmlNavItem(file, "subscribe", "", baseSubscribe); + if (error) return error; + } + return 0 + || htmlNavItem(file, "write", "mailto:", baseAddress) + || templateRender(file, TEMPLATE(</ul></nav>), NULL, NULL); +} + int htmlIndexOpen(FILE *file) { - const char *template = TEMPLATE( + const char *head = TEMPLATE( <header class="index"> <h1>[title]</h1> - <nav> - <ul> - <li><a href="index.atom">follow</a></li> - <li><a href="mailto:[addr]">write</a></li> - </ul> - </nav> - </header> - <main class="index"> - <ol> ); struct Variable vars[] = { { "title", baseTitle }, - { "addr", baseAddress }, {0}, }; - return templateRender(file, template, vars, escapeXML); + const char *tail = TEMPLATE( + </header> + <main class="index"> + <ol> + ); + return 0 + || templateRender(file, head, vars, escapeXML) + || htmlIndexNav(file) + || templateRender(file, tail, NULL, NULL); } static char *htmlIndexURL(const struct Envelope *envelope) { |