summaryrefslogtreecommitdiff
path: root/rs.sh
blob: 19255fda507c09b1b0a28b1f21608348ea2fa1d1 (plain) (blame)
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
#!/bin/sh

#    Seen, a simple static blog generator
#
#    Copyright (C) 2021 Vitali64 <vitali64pmemail@protonmail.com>
#    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/>.

die() {
	echo "-> [$(date +%R)] (!) ERROR: Unexpected error, please report : $1 (!)"
	exit 1
}

# Articles
articles="$(find articles/*.md|sed -e 's@.md@@g' -e 's@articles/@@g')" || die "Unknown error"

echo "Copyright (C) 2021 Vitali64 <vitali64pmemail@protonmail.com>"
echo "This program comes with ABSOLUTELY NO WARRANTY."
echo "This is free software, and you are welcome to modify it,"
echo "use it where you see fit, and redistribute it"
echo "under certain conditions; type './seen.sh --license' for details."
echo
echo "-> [$(date +%R)] Generating RSS feed ..."

touch "www/rss.xml"

# Set the defaults
rssBlogTitle="blog"
rssBlogDescription="It's a blog"
. "./rss.cfg" # Override the defaults
# Header of the RSS XML file
echo "-> [$(date +%R)] Inserting XML header ..."
printf '%s\n' '<rss version="2.0">' > "www/rss.xml"
printf '%s\n' '<channel>' >> "www/rss.xml"
printf '%s\n' "<title>${rssBlogTitle}</title>" >> "www/rss.xml"
printf '%s\n' "<link>BLANK</link>" >> "www/rss.xml"
printf '%s\n' "<description>$rssBlogDescription</description>" >> "www/rss.xml"

# Items
for line in ${articles}
do
	echo "-> [$(date +%R)] Inserting XML ${line} item ..."
	. "articles/${line}.cfg"
	printf '%s\n' '<item>' >> "www/rss.xml"
	printf '%s\n' "<title>${name}</title>" >> "www/rss.xml"
	printf '%s\n' "<description>$(cat articles/${line}.md)</description>" >> "www/rss.xml"
	printf '%s\n' '</item>' >> "www/rss.xml"
done

# Footer of the RSS XML file
echo "-> [$(date +%R)] Inserting XML footer ..."
printf '%s\n' '</channel>' >> "www/rss.xml"
printf '%s\n' '</rss>' >> "www/rss.xml"

echo "-> [$(date +%R)] RSS generation done!"