apps: add simple site-search app

This commit is contained in:
Kurt H Maier 2020-05-25 17:13:01 -07:00
parent e11dc36640
commit 930d4eb9f8
3 changed files with 48 additions and 0 deletions

16
apps/search/HOWTO Normal file
View file

@ -0,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.

29
apps/search/app.rc Executable file
View file

@ -0,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>'
}

View file

@ -0,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>