aboutsummaryrefslogtreecommitdiff
path: root/recover.sh
blob: 5ce01718d02c8881b750bb373cfd646907a696f0 (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
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p dateutils
LIMIT=5000
read_dom () {
    ORIGINAL_IFS=$IFS
    IFS=\>
    read -d \< ENTITY CONTENT
    IFS=$ORIGINAL_IFS
}

repair_post_dates() {
    local count=0
    local url=https://peppe.rs/posts/
    while read_dom; do
        ((count++))
        if [ "$count" -ge "$LIMIT" ]; then
            exit
        fi
        if [[ $ENTITY = "link" ]] ; then
            local _f=${CONTENT##$url}
            local f="posts/${_f%%/}.md"
        elif [[ $ENTITY = "pubDate" ]] ; then
            local d=$CONTENT
            repair "$d" "$f"
        fi
    done
}

repair_art_dates() {
    local f d
    while mapfile -t -n 2 a && ((${#a[@]})); do
        f=${a[0]}
        d=${a[1]}

        f=${f##src=\"/}
        d=$(dateconv -i '%d/%m — %Y' "$d")

        repair "$d" "$f"
    done
}

repair() {
    echo "[+] repairing $2"
    touch -am -d "$1" "$2"
}

grep -B1 pubDate docs/index.xml | repair_post_dates
grep -Eo \
    -e 'src="/art/.*.png' \
    -e '[0-9]{2}/[0-9]{2}...[0-9]{4}' \
    docs/art/index.html | repair_art_dates