2022-06-07 16:39:32 +00:00
#!/bin/sh
# Get webring links to append to the CSV before building
# Some webrings require an iframe or scripts, but I want a plain static
# first-party HTML+CSS page. This script fetches webring links by
# parsing the iframes and appends appropriate values to my webrings.csv file.
2023-11-25 21:40:52 +00:00
#shellcheck disable=SC3040 # This only sets pipefail if it's available (e.g. in Bash, Zsh) and otherwise does nothing (in other POSIX shells like Busybox sh and dash)
set -o pipefail 2>/dev/null
2022-06-07 16:39:32 +00:00
set -e -u
# the name of this program
progname = " $( basename " $0 " ) "
dirname = " $( dirname " $0 " ) "
2024-07-14 06:08:34 +00:00
webrings_src = " $dirname /../assets/csv/webrings.base.csv "
webrings_dest = " $dirname /../assets/csv/webrings.csv "
2022-06-07 16:39:32 +00:00
help_text = " Usage: $progname [OPTION...]
Update webrings.csv with new prev/next links, to avoid iframes/scripts
Options:
-h Print this help and exit
-d Dry run; just print results, don' t update webrings.csv
"
usage( ) {
printf '%s' " $help_text "
}
# when the user passess bad args, send a msg to stderr and exit
# usage: bad_option <option> <reason>
bad_option( ) {
echo " $progname : option $1 : $2 " >& 2
usage >& 2
exit 1
}
dry_run = '0'
while getopts "hd" flags; do
case $flags in
h)
usage
exit 0
; ;
d)
dry_run = '1'
shift
; ;
*)
bad_option " $flags " 'invalid option'
; ;
esac
done
2022-06-12 20:48:16 +00:00
endless_orbit( ) {
printf 'Endless Orbit,'
2023-11-15 05:39:53 +00:00
curl -sSL --compressed https://linkyblog.neocities.org/onionring/onionring-variables.js \
2023-11-24 03:06:46 +00:00
| grep -C 1 https://seirdy.one/ \
| tr -d "'\n" | sed 's|https://seirdy.one/|https://linkyblog.neocities.org/webring.html|'
2023-11-15 05:39:53 +00:00
echo 'null'
2022-06-07 16:39:32 +00:00
}
2024-02-27 08:29:54 +00:00
focus_first( ) {
printf 'Focus First,'
curl -sSL --compressed https://owlsroost.xyz/webring/onionring-variables.js \
| grep -C 1 https://seirdy.one/ \
| tr -d "'\r\n\t" | sed 's|https://seirdy.one/|https://owlsroost.xyz/webring/index.html|'
echo 'null'
}
all_lines( ) {
endless_orbit
focus_first
}
2022-06-07 16:39:32 +00:00
if [ " $dry_run " = '1' ] ; then
2024-04-05 21:11:02 +00:00
all_lines
2022-06-12 20:48:16 +00:00
elif [ -f " $webrings_dest " ] ; then
2023-11-24 03:06:46 +00:00
echo "webrings file already generated"
2022-06-07 16:39:32 +00:00
else
2024-02-27 08:29:54 +00:00
all_lines | cat " $webrings_src " - >" $webrings_dest "
2022-06-07 16:39:32 +00:00
fi
# vi:ft=sh