all repos — site @ 003b3e29dc4b4a58518e1e8301380419445e522c

source for my site, found at icyphox.sh

bin/plaintext.sh (view raw)

 1#!/bin/sh 
 2
 3# from the pure sh bible; see: 
 4# https://github.com/dylanaraps/pure-sh-bible#get-the-base-name-of-a-file-path
 5
 6if ! command -v lynx &> /dev/null
 7then
 8    printf '%s\n' "lynx not found, not going to run"
 9    exit
10fi
11
12for p in build/blog/**/index.html; do
13    ppath="${p%%\/index.html}"
14    pname="${ppath##build\/blog\/}"
15
16    temp="$ppath/temp.html"
17    # Not POSIX, I know
18    sed -e '29,34d' "$p" > "$temp"
19    cat "$temp" | awk -v OFS='\n\n' '/class="muted"/{n=3}; n {n--; next;} 1' > "$temp.new"
20    mv "$temp.new" "$temp"
21
22    txt="pages/txt/$pname.txt"
23    lynx -dump "$temp" | tail -n +1 > "$txt"
24    rm "$temp"
25    sed -i 's/file:\/\/\//https:\/\/icyphox\.sh\//' "$txt"
26done