aboutsummaryrefslogtreecommitdiff
path: root/search/index.cgi
blob: 86df972fb51a4f5301ac316fc2383859d8513746 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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'