the ugly shellscript powering https://oppi.li
at main 1.1 kB view raw
1#! /usr/bin/env nix-shell 2#! nix-shell -i bash -p dateutils 3LIMIT=5000 4read_dom () { 5 ORIGINAL_IFS=$IFS 6 IFS=\> 7 read -d \< ENTITY CONTENT 8 IFS=$ORIGINAL_IFS 9} 10 11repair_post_dates() { 12 local count=0 13 local url=https://peppe.rs/posts/ 14 while read_dom; do 15 ((count++)) 16 if [ "$count" -ge "$LIMIT" ]; then 17 exit 18 fi 19 if [[ $ENTITY = "link" ]] ; then 20 local _f=${CONTENT##$url} 21 local f="posts/${_f%%/}.md" 22 elif [[ $ENTITY = "pubDate" ]] ; then 23 local d=$CONTENT 24 repair "$d" "$f" 25 fi 26 done 27} 28 29repair_art_dates() { 30 local f d 31 while mapfile -t -n 2 a && ((${#a[@]})); do 32 f=${a[0]} 33 d=${a[1]} 34 35 f=${f##src=\"/} 36 d=$(dateconv -i '%d/%m — %Y' "$d") 37 38 repair "$d" "$f" 39 done 40} 41 42repair() { 43 echo "[+] repairing $2" 44 touch -am -d "$1" "$2" 45} 46 47grep -B1 pubDate docs/index.xml | repair_post_dates 48grep -Eo \ 49 -e 'src="/art/.*.png' \ 50 -e '[0-9]{2}/[0-9]{2}...[0-9]{4}' \ 51 docs/art/index.html | repair_art_dates