shithub: werc

Download patch

ref: 300999d3e739e00096c1bc8c3c6e9850ca28a206
parent: 3796828c73dc502b836518b73ef6d0b9b764dfe5
author: khm <khm@9front.org>
date: Mon May 25 13:13:01 EDT 2020

apps: add simple site-search app

diff: cannot open b/apps/search//null: file does not exist: 'b/apps/search//null'
--- /dev/null
+++ b/apps/search/HOWTO
@@ -1,0 +1,16 @@
+The default path for site search is /_search/.  Assuming you want to keep
+that default, you could enable site search like so:
+
+
+mkdir -p /www/werc/sites/MYSITE/_search/_werc/
+echo 'conf_enable_search' > /www/werc/sites/MYSITE/_search/_werc/config
+mkdir -p /www/werc/sites/MYSITE/_werc/lib/
+cp /www/werc/apps/search/footer.inc.sample /www/werc/sites/MYSITE/_werc/lib/
+
+Searches will POST to /_search/ and from there get redirected to Duck Duck 
+Go with a site:$SERVER_NAME prefix.  To have the search path URL be some-
+thing differen, you'll have to edit line 23 of app.rc to point to the new
+path.
+
+TODO: make it automatically work no matter which directory the app is 
+enabled in.
--- /dev/null
+++ b/apps/search/app.rc
@@ -1,0 +1,29 @@
+fn conf_enable_search {
+    enable_search=yes
+    conf_enable_app search
+		pageTitle='Site Search'
+}
+
+
+fn search_init {
+	get_post_args q
+	if (! ~ $#q 0) {
+		redirect_string = 'https://duckduckgo.com/?q=site:'$SERVER_NAME^'+'^$"q
+		http_redirect $redirect_string '302 Found'
+	}
+	if not {
+		handler_body_main='search_body'
+	}
+}
+
+fn search_body {
+    echo '
+<h1>Site search</h1>
+<h3>using DuckDuckGo</h3>
+<form action="/_search/" method="POST">
+<input type="text" name="q" placeholder="Search text...">
+<input type="submit" value="Search">
+</form>'
+
+}
+
--- /dev/null
+++ b/apps/search/footer.inc.sample
@@ -1,0 +1,3 @@
+<div><a href="http://werc.cat-v.org">Powered by werc</a></div>
+
+<div><form action="/_search/" method="POST"><input type="text" name="q" placeholder="Site search..."><input type="submit" display="Search"></form></div>