commit e3c9b6bb3857c42346c59fa3be4a925318dfacc4 parent a2f715492249b077bf33b5304f8e6400d5933dda Author: Jake Bauer <jbauer@paritybit.ca> Date: Mon, 8 Jun 2020 01:50:03 -0400 Auto-paste generated blogroll onto links page Diffstat:
M | generate-blogroll.sh | | | 37 | ++++++++++++++++++++++++++++++++++--- |
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/generate-blogroll.sh b/generate-blogroll.sh @@ -24,18 +24,49 @@ set -o errexit set -o nounset IFS=$(printf '\n\t') +# Check if we have the programs we need +if [ ! -x "$(command -v newsboat)" ]; then + echo "The program 'newsboat' is needed but was not found." + exit 1 +fi +if [ -x "$(command -v nvim)" ]; then + vim_ver="nvim" +elif [ ! -x "$(command -v vim)" ]; then + vim_ver="vim" +else + echo "Either vim or nvim is needed but was not found." + exit 1 +fi + feed_list=$(newsboat -e | grep outline) > blogroll-unsorted.md for item in $feed_list; do - xml_url=$(echo "$item" | awk '{print $3}' | cut -d'=' -f2- | tr -d \") - http_url=$(echo "$item" | awk '{print $4}' | cut -d'=' -f2- | tr -d \") - title=$(echo "$item" | awk '{$1=$2=$3=$4=""; print $0}' | cut -d'=' -f2- | tr -d \" | sed -E 's/\/>$//') + xml_url=$(echo "$item" | awk '{$1=$2=""; print $3}' \ + | cut -d'=' -f2- | tr -d \") + http_url=$(echo "$item" | awk '{$1=$2=$3=""; print $4}' \ + | cut -d'=' -f2- | tr -d \") + title=$(echo "$item" | awk '{$1=$2=$3=$4=""; print $0}' \ + | cut -d'=' -f2- | tr -d \" | sed -E 's/\/>$//') echo "* [$title]($http_url) ([feed]($xml_url))" >> blogroll-unsorted.md done sort blogroll-unsorted.md > blogroll.md rm blogroll-unsorted.md +# Replace existing content in blogroll.md with new list of feeds +echo ":%y +:e pages/links.md +/BLOGROLL_BEGIN +j +V +/BLOGROLL_END +2k +p +:wq" > script.vim +"$vim_ver" -s script.vim blogroll.md +rm script.vim +rm blogroll.md + exit 0