all repos — site @ fc5cc56b1446882232405a61b3545939eb0fbd35

source for my site, found at icyphox.sh

bin/plaintext.sh (view raw)

 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
#!/bin/sh 

# from the pure sh bible; see: 
# https://github.com/dylanaraps/pure-sh-bible#get-the-base-name-of-a-file-path

if ! command -v lynx &> /dev/null
then
    printf '%s\n' "lynx not found, not going to run"
    exit
fi

for p in build/blog/**/index.html; do
    ppath="${p%%\/index.html}"
    pname="${ppath##build\/blog\/}"

    temp="$ppath/temp.html"
    # Not POSIX, I know
    sed -e '29,34d' "$p" > "$temp"
    cat "$temp" | awk -v OFS='\n\n' '/class="muted"/{n=3}; n {n--; next;} 1' > "$temp.new"
    mv "$temp.new" "$temp"

    txt="pages/txt/$pname.txt"
    lynx -dump "$temp" | tail -n +1 > "$txt"
    rm "$temp"
    sed -i 's/file:\/\/\//https:\/\/icyphox\.sh\//' "$txt"
done