tildelog/lib/make_rss.sh

53 lines
1.8 KiB
Bash
Raw Normal View History

2020-12-19 19:43:21 +00:00
#!/usr/bin/env bash
# Generate the feed file
2021-03-12 09:13:56 +00:00
declare blog_feed
declare date_format_full
declare global_title
declare global_url
declare global_description
declare index_file
declare number_of_feed_articles
declare cut_do
2020-12-19 19:43:21 +00:00
make_rss() {
2021-03-12 09:13:56 +00:00
2020-12-19 19:43:21 +00:00
echo -n "Making RSS "
rssfile=$blog_feed.$RANDOM
while [[ -f $rssfile ]]; do rssfile=$blog_feed.$RANDOM; done
{
pubdate=$(LC_ALL=C date +"$date_format_full")
echo '<?xml version="1.0" encoding="UTF-8" ?>'
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">'
2020-12-19 19:43:21 +00:00
echo "<channel><title>$global_title</title><link>$global_url/$index_file</link>"
echo "<description>$global_description</description><language>en</language>"
echo "<lastBuildDate>$pubdate</lastBuildDate>"
echo "<pubDate>$pubdate</pubDate>"
echo "<atom:link href=\"$global_url/$blog_feed\" rel=\"self\" type=\"application/rss+xml\">"
n=0
while IFS='' read -r i; do
is_boilerplate_file "$i" && continue
((n >= number_of_feed_articles)) && break # max 10 items
echo -n "." 1>&3
echo '<item><title>'
2020-12-19 19:43:21 +00:00
get_post_title "$i"
echo '</title><description><![CDATA['
2020-12-19 19:43:21 +00:00
get_html_file_content 'text' 'entry' "$cut_do" <"$i"
echo "]]></description><link>$global_url/${i#./}</link>"
echo "<guid>$global_url/$i</guid>"
echo "<dc:creator>$(get_post_author "$i")</dc:creator>"
2020-12-19 19:43:21 +00:00
echo "<pubDate>$(LC_ALL=C date -r "$i" +"$date_format_full")</pubDate></item>"
n=$((n + 1))
2020-12-19 19:43:21 +00:00
done < <(ls -t ./*.html)
echo '</channel></rss>'
} 3>&1 >"$rssfile"
echo ""
mv "$rssfile" "$blog_feed"
chmod 644 "$blog_feed"
}