~rumpelsepp/homepage

ref: 2a0829d7d5c82198e590e856efc864471be97a18 homepage/_stuff/list2adoc -rwxr-xr-x 865 bytes
2a0829d7Stefan Tatschner add degoogle | A huge list of alternatives to Google products. Privacy tips, tricks, and links. 5 months ago
                                                                                
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
#!/bin/bash

set -u

# $1: url
gettitle() {
    curl -Ls "$1" | grep -iPo '(?<=<title>)(.*)(?=</title>)'
}

main() {
    local infile
    infile="$1"

    while read line; do
        if [[ ! "$line" =~ ^\*.* ]]; then
            echo "$line"
            continue
        fi

        local url
        local title
        local rfc

        rfc=""
        url=""
        line="${line//\* /}"
        if [[ "$line" =~ ^rfc[0-9]+ ]]; then
            rfc="$line"
            url="https://tools.ietf.org/html/$rfc"
        else
            url="$(echo "${line//\* /}" | sed 's/\s+$//')"
        fi

        title="$(gettitle "$url")"

        if [[ "$rfc" != "" ]]; then
            echo "* $url[$(echo $rfc | awk '{ print toupper($0) }')] -- $(echo $title | sed 's/.*-\s//')"
        else
            echo "* $url[$title]"
        fi
    done < "$infile"
}

main "$@"