aboutsummaryrefslogtreecommitdiff
path: root/search/index.cgi
blob: 56dc145d15b2bc2bb0b593c1338c43cae025ec64 (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
50
51
52
53
54
55
56
57
58
59
60
#!/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
        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
      )

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'