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.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/html.c b/html.c
index 49b65e9..f5ea6bd 100644
--- a/html.c
+++ b/html.c
@@ -48,6 +48,30 @@ enum kcgi_err htmlHead(struct khtmlreq *html, const char *title) {
 		|| khtml_closeelem(html, 1);
 }
 
+enum kcgi_err htmlScopeFields(struct khtmlreq *html, struct Scope scope) {
+	if (scope.network) {
+		enum kcgi_err error = khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "hidden",
+			KATTR_NAME, Keys[Network].name,
+			KATTR_VALUE, scope.network,
+			KATTR__MAX
+		);
+		if (error) return error;
+	}
+	if (scope.context) {
+		enum kcgi_err error = khtml_attr(
+			html, KELEM_INPUT,
+			KATTR_TYPE, "hidden",
+			KATTR_NAME, Keys[Context].name,
+			KATTR_VALUE, scope.context,
+			KATTR__MAX
+		);
+		if (error) return error;
+	}
+	return KCGI_OK;
+}
+
 enum kcgi_err
 htmlNav(struct khtmlreq *html, struct Scope scope) {
 	enum kcgi_err error = 0
@@ -97,7 +121,7 @@ htmlNav(struct khtmlreq *html, struct Scope scope) {
 		(scope.context ? scope.context : scope.network ? scope.network : "")
 	);
 
-	error = 0
+	return 0
 		|| khtml_closeelem(html, 1)
 		|| khtml_attr(
 			html, KELEM_FORM,
@@ -105,6 +129,7 @@ htmlNav(struct khtmlreq *html, struct Scope scope) {
 			KATTR_ACTION, Pages[Search],
 			KATTR__MAX
 		)
+		|| htmlScopeFields(html, scope)
 		|| khtml_attr(
 			html, KELEM_INPUT,
 			KATTR_TYPE, "search",
@@ -117,32 +142,8 @@ htmlNav(struct khtmlreq *html, struct Scope scope) {
 			KATTR_TYPE, "submit",
 			KATTR_VALUE, label,
 			KATTR__MAX
-		);
-	if (error) return error;
-
-	if (scope.network) {
-		error = khtml_attr(
-			html, KELEM_INPUT,
-			KATTR_TYPE, "hidden",
-			KATTR_NAME, Keys[Network].name,
-			KATTR_VALUE, scope.network,
-			KATTR__MAX
-		);
-		if (error) return error;
-	}
-
-	if (scope.context) {
-		error = khtml_attr(
-			html, KELEM_INPUT,
-			KATTR_TYPE, "hidden",
-			KATTR_NAME, Keys[Context].name,
-			KATTR_VALUE, scope.context,
-			KATTR__MAX
-		);
-		if (error) return error;
-	}
-
-	return khtml_closeelem(html, 2);
+		)
+		|| khtml_closeelem(html, 2);
 }
 
 static const char *SourceURL = "https://git.causal.agency/scooper";