aboutsummaryrefslogtreecommitdiff
path: root/search/index.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'search/index.cgi')
-rwxr-xr-xsearch/index.cgi49
1 files changed, 49 insertions, 0 deletions
diff --git a/search/index.cgi b/search/index.cgi
new file mode 100755
index 0000000..86df972
--- /dev/null
+++ b/search/index.cgi
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+printf "Content-Type: text/html\n\n"
+
+IFS='&'
+
+for arg in $QUERY_STRING; do
+ case $arg in
+ q=*)
+ WORDS=`echo $arg | sed 's/q=//'`
+ ;;
+ esac
+done
+
+RETURN=$(
+find ../ -name "*.html" -not -path "../search/*" |
+ while read i; do
+ RESULTS=`grep "$WORDS" $i`
+ if [ ! -z "$RESULTS" ]; then
+ TITLE=`grep "<title>.*</title>" $i | sed 's/<[^>]*>//g' | sed 's/[ ]*//'`
+ echo $i | sed -E 's/[\.\/]*(.*)/<a href="\/\1"><h4>'$TITLE'<\/h4><\/a>/g'
+ echo "<ul>"
+ grep "$WORDS" $i \
+ | sed -E 's/<[^>]*>//g' \
+ | sed -E 's/[ ]*(.*)/<li>\1<\/li>/g' \
+ | sed -E 's/('$WORDS')/<span style="background: yellow">\1<\/span>/g'
+ echo "</ul>"
+ fi
+ done
+ )
+
+while read -r line; do
+ if [ $line == '<!-- DELIMITER -->' ]; then
+ if [ -z $RETURN ]; then
+ echo "<p>Nessun risultato</p>"
+ else
+ echo $RETURN
+ fi
+ else
+ echo $line
+ fi
+done < index.html
+
+#grep -r "$WORDS" ../ --exclude-dir=search --exclude-dir=assets
+# | sed -E 's/รจ/\&egrave;/g' \
+# | sed -E 's/<[^>]*>//g' \
+# | sed -E 's/[\.\/]*([^:]*):[ ]*(.*)/\/\1:\2/g' \
+# | sed -E 's/([^:]*):(.*)/<li><a href="\1">\2<\/a><\/li>/g'
+