summary refs log tree commit diff
path: root/server.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-11 14:04:25 -0400
committerJune McEnroe <june@causal.agency>2020-07-11 14:04:25 -0400
commit24c7965d9d0aaf27985d29c5cbb12a4e08ac7d9c (patch)
tree2a9e3955d59c375edb7d02ae0bd195bf966d57ea /server.h
parentImplement basic search page (diff)
downloadscooper-24c7965d9d0aaf27985d29c5cbb12a4e08ac7d9c.tar.gz
scooper-24c7965d9d0aaf27985d29c5cbb12a4e08ac7d9c.zip
Factor out "scope" of pages
Use this to keep the search query around and hide network and context
from the search results if the scope is already limited.
Diffstat (limited to 'server.h')
-rw-r--r--server.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/server.h b/server.h
index 502e228..318d103 100644
--- a/server.h
+++ b/server.h
@@ -171,10 +171,24 @@ static inline enum kcgi_err httpFail(struct kreq *req, enum khttp http) {
 		|| khttp_printf(req, "%s\n", khttps[http]);
 }
 
+struct Scope {
+	const char *network;
+	const char *context;
+	const char *query;
+};
+
+static inline struct Scope htmlScope(struct kreq *req) {
+	struct Scope s = {0};
+	if (req->fieldmap[Network]) s.network = req->fieldmap[Network]->parsed.s;
+	if (req->fieldmap[Context]) s.context = req->fieldmap[Context]->parsed.s;
+	if (req->fieldmap[Query]) s.query = req->fieldmap[Query]->parsed.s;
+	return s;
+}
+
 extern const char *htmlStylesheet;
 enum kcgi_err htmlHead(struct khtmlreq *html, const char *title);
-enum kcgi_err htmlNav(
-	struct khtmlreq *html, const char *network, const char *context
-);
+enum kcgi_err htmlNav(struct khtmlreq *html, struct Scope scope);
 enum kcgi_err htmlFooter(struct khtmlreq *html);
-enum kcgi_err htmlEvent(struct khtmlreq *html, struct Event event);
+enum kcgi_err htmlEvent(
+	struct khtmlreq *html, struct Scope scope, struct Event event
+);