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