aboutsummaryrefslogtreecommitdiff
path: root/search/index.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'search/index.cgi')
-rwxr-xr-xsearch/index.cgi70
1 files changed, 35 insertions, 35 deletions
diff --git a/search/index.cgi b/search/index.cgi
index 56dc145..6bcf0d2 100755
--- a/search/index.cgi
+++ b/search/index.cgi
@@ -1,5 +1,38 @@
#!/bin/sh
+remove_nav_and_footer()
+{
+ cat $1 | \
+ awk 'BEGIN { del=0 } /<nav/ { del=1 } del<=0 { print } /nav>/ { del -= 1 }' | \
+ awk 'BEGIN { del=0 } /<footer/ { del=1 } del<=0 { print } /footer>/ { del -= 1 }'
+}
+
+build_search_list()
+{
+ find ../ -name "*.html" -not -path "../search/*" |
+ while read html_file; do
+ for WORD in $WORDS; do
+ # This line removes the navigation bar
+ RESULTS=$(remove_nav_and_footer $html_file | grep -i "$WORD")
+
+ if [ ! -z "$RESULTS" ]; then
+ # For some reason, CGI doesn't print &. So, we replace unicode codes with the character
+ TITLE=$(grep "<title>.*</title>" $html_file | sed 's/<[^>]*>//g' | sed 's/[ ]*//' \
+ | sed 's/&agrave;/à/g')
+
+ HREF=$(echo $html_file | sed 's/^[\.]*//g')
+ echo '<a href="'$HREF'"><h4>'$TITLE'</h4></a>'
+ echo "<ul>"
+ remove_nav_and_footer $html_file | grep -i "$WORD" \
+ | sed -E 's/<[^>]*>//g' \
+ | sed -E 's/[ ]*(.*)/<li>\1<\/li>/g' \
+ | sed -E 's/('$WORD')/<span style="background: yellow">\1<\/span>/Ig'
+ echo "</ul>"
+ fi
+ done
+ done
+}
+
printf "Content-Type: text/html\n\n"
IFS='&'
@@ -12,33 +45,7 @@ for arg in $QUERY_STRING; do
esac
done
-RETURN=$(
-find ../ -name "*.html" -not -path "../search/*" |
- while read i; do
- for WORD in $WORDS
- do
- RESULTS=`grep "$WORD" $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 "$WORD" $i \
- | sed -E 's/<[^>]*>//g' \
- | sed -E 's/[ ]*(.*)/<li>\1<\/li>/g' \
- | sed -E 's/('$WORD')/<span style="background: yellow">\1<\/span>/g'
- echo "</ul>"
-# 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
- done
- )
+RETURN=$(build_search_list)
while read -r line; do
if [ $line == '<!-- DELIMITER -->' ]; then
@@ -48,13 +55,6 @@ while read -r line; do
echo $RETURN
fi
else
- echo $line
+ 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'
-