all repos — site @ 01526772eb9929ffa5a13c54d95001a8f074ce78

source for my site, found at icyphox.sh

Better plaintext generation using lynx
Anirudh Oppiliappan x@icyphox.sh
Mon, 07 Dec 2020 17:38:51 +0530
commit

01526772eb9929ffa5a13c54d95001a8f074ce78

parent

bec9dd7831d57d7e8c092a4cbe9e941dde0f5a80

1 files changed, 13 insertions(+), 15 deletions(-)

jump to
M bin/plaintext.shbin/plaintext.sh

@@ -2,22 +2,20 @@ #!/bin/sh

# from the pure sh bible; see: # https://github.com/dylanaraps/pure-sh-bible#get-the-base-name-of-a-file-path -basename() { - dir=${1%${1##*[!/]}} - dir=${dir##*/} - dir=${dir%"$2"} - base="${dir:-/}" -} +mkdir -p build/txt +for p in build/blog/**/index.html; do + ppath="${p%%\/index.html}" + pname="${ppath##build\/blog\/}" -mkdir "build/txt/" + 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" -for p in pages/blog/*.md; do - basename "$p" - no_ext="${base%.*}" -# [ "$base" != "_index.md" ] && { -# pandoc --quiet -s -f "markdown+gutenberg" \ -# "$p" -o "pages/txt/$no_ext.txt" -# } - cp "$p" "build/txt/$no_ext.txt" + txt="build/txt/$pname.txt" + lynx -dump "$temp" | tail -n +1 > "$txt" + rm "$temp" + sed -i 's/file:\/\/\//https:\/\/icyphox\.sh\//' "$txt" done