blob: b4e18080d38ab9f585c473136740d934579bef46 (
plain)
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
85
86
|
#!/usr/bin/env bash
# settings
TYEAR="$(date +%Y)"
TITLE="Bloggings"
YLINK="https://wittamore.fr/articles/$TYEAR"
FDESC="Ramblings from Brittany"
WSITE="https://wittamore.fr"
RLINK="$WSITE/rss.xml"
FEEDN="/home/philip/web/rss.xml"
ARTDR="/home/philip/web/articles/$TYEAR"
UPDAT="$(date --iso-8601=ns)"
# convert tring to htmlentities
htmlentities () {
echo $1 | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'
}
# Build RSS header & footer
header () {
echo "<?xml version='1.0' encoding='UTF-8' ?>
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
<channel>
<title>$TITLE</title>
<link>$WSITE</link>
<description>$FDESC</description>
<lastBuildDate>$UPDAT</lastBuildDate>
<atom:link href='$RLINK' rel='self' type='application/rss+xml' />
" >> ~/feedtop
}
footer () {
echo "
</channel>
</rss>
" >> ~/feedbottom
}
# Function: Build Item add to feed
builditem () {
echo "<item>
<title>$POSTTIT</title>
<pubDate>$POSTDAT</pubDate>
<author>Philip A. Wittamore</author>
<link>$POSTADD</link>
<guid>$POSTADD</guid>
<category> </category>
<description><![CDATA[$POSTDES]]></description>
</item>" >> ~/feed
}
# Function: Concatenate everything
combine () {
header
footer
cat ~/feedtop ~/feed > ~/feedtb
cat ~/feedtb ~/feedbottom > $FEEDN
rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
}
# Run through files and create rss.xml
if [[ -f $FEEDN ]]; then
rm $FEEDN
fi
touch $FEEDN
mapfile -t ARTICLEARRAY < <(ls -t --time=birth "$ARTDR"/*.html)
postNum=0
for POSTS in "${ARTICLEARRAY[@]}"; do
((postNum+=1))
POST=$POSTS
POSTTIT="$(grep -o '<h2>.*</h2>' $POST | sed 's/\(<h2>\|<\/h2>\)//g')"
POSTDAT="$(grep -o '<h3>.*</h3>' $POST | sed 's/\(<h3>\|<\/h3>\)//g')"
# extract article html
POSTDES="$(awk '/<article>/,/<\/article>/' $POST | sed -E -e '/(<h2|<h3|article\>)/d')"
POSTNAM="$(htmlentities "${POST##*/}")"
POSTTIT="$(htmlentities "$POSTTIT")"
POSTADD="$YLINK/$POSTNAM"
builditem "$POST"
done
combine
exit
|