~jbauer/paritybit.ca

paritybit.ca/generate-blogroll.sh -rwxr-xr-x 2.3 KiB
c8b1e086Jake Bauer Publish new blog post 2 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh

# generate-blogroll
# A POSIX shell script to generate the blogroll list for paritybit.ca.
# NOTE: See the README for the expected format of md files.
#
# Copyright (C) 2020  Jake Bauer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# POSIX Shell "Strict Mode"
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

echo "Generating new blogroll..."
for item in $feed_list; do
    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 "Updating pages/links.md..."
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

./compile pages/links.md

# Generate OPML file
echo "Generating OPML..."
newsboat -e > public/blogroll.opml

# Send the new OPML file to the site
echo "Uploading blogroll.opml..."
cd public && rsync -rR blogroll.opml paritybit.ca:uploads/ && cd ..

exit 0