53 lines
1.8 KiB
Bash
53 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Generate the feed file
|
|
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
|
|
make_rss() {
|
|
|
|
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/">'
|
|
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>'
|
|
get_post_title "$i"
|
|
echo '</title><description><![CDATA['
|
|
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>"
|
|
echo "<pubDate>$(LC_ALL=C date -r "$i" +"$date_format_full")</pubDate></item>"
|
|
|
|
n=$((n + 1))
|
|
done < <(ls -t ./*.html)
|
|
|
|
echo '</channel></rss>'
|
|
} 3>&1 >"$rssfile"
|
|
echo ""
|
|
|
|
mv "$rssfile" "$blog_feed"
|
|
chmod 644 "$blog_feed"
|
|
}
|