convert to atom feeds

This commit is contained in:
nytpu 2020-09-09 19:40:24 -06:00
parent 9f97b3b6bf
commit e8325692d4
Signed by: nytpu
GPG Key ID: ECCDC07B337B8F5B
1 changed files with 38 additions and 28 deletions

View File

@ -21,58 +21,68 @@ make_globals() {
global_description="yet another tech gemlog"
global_url="gemini://nytpu.com/gemlog/" # link to base url of blog
global_author="nytpu"
global_author_email="alex@nytpu.com"
global_author_url="gemini://nytpu.com/"
global_license="CC by"
gemlog_feed="feed.rss" # filename of the rss feed
gemlog_feed="atom.xml" # filename of the atom feed
number_of_feed_articles="50" # number of posts in rss feed
feed_base_url="https://nytpu.com/files/" # base url that the feed is hosted at
index="index.gmi" # main page, not recommended to change
# don't change these
date_format_full="%a, %d %b %Y %H:%M:%S %z"
date_format_timestamp="%Y%m%d%H%M.%S"
gemlog_sh_link="https://tildegit.org/nytpu/gemlog.sh"
date_format_8601="+%Y-%m-%dT%H:%M:%S%:z"
}
get_post_title() {
cat "$1" | perl -lne 's/#{1,3}\s+(.*)/\1/ or next; print; exit'
}
# from bashblog (https://tildegit.org/team/bashblog)
# bashblog is licensed under the gnu gplv3
make_rss() {
echo "Making RSS"
make_atom() {
echo "Making Atom"
rssfile="$gemlog_feed.$RANDOM"
while [[ -f $rssfile ]]; do rssfile="$gemlog_feed.$RANDOM"; done
atomfile="$gemlog_feed.$RANDOM"
while [[ -f $atomfile ]]; do atomfile="$gemlog_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</link>"
echo "<description>$global_description</description><language>en</language>"
echo "<lastBuildDate>$pubdate</lastBuildDate>"
echo "<pubDate>$pubdate</pubDate>"
echo "<atom:link href=\"$feed_base_url$gemlog_feed\" rel=\"self\" type=\"application/rss+xml\" />"
pubdate=$(date "$date_format_8601")
cat << EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>$global_title</title>
<subtitle>$global_description</subtitle>
<link rel='self' href='$feed_base_url$gemlog_feed'/>
<link rel='alternate' href='$global_url$index'/>
<updated>$pubdate</updated>
<author>
<name>$global_author</name>
<email>$global_author_email</email
<uri>$global_author_url</uri>
</author>
<id>$global_url</id>
<generator uri='$gemlog_sh_link'>gemlog.sh</generator>
<rights>© $global_author - $global_license</rights>
EOF
n=0
while IFS='' read -r i; do
((n >= number_of_feed_articles)) && break
echo "<item><title>"
get_post_title "$i"
echo "</title><description>You need a gemini protocol client to view this post.&lt;br&gt;If you have one installed, click here to open the post: &lt;a href=\"$global_url${i#'./'}\"&gt;$global_url${i#'./'}&lt;/a&gt;</description><link>$global_url${i#'./'}</link>"
echo "<guid>$global_url${i#'./'}</guid>"
echo "<dc:creator>$global_author</dc:creator>"
echo "<pubDate>$(LC_ALL=C date -r "$i" +"$date_format_full")</pubDate></item>"
printf "\n <entry>\n <title>"
get_post_title "$i" | tr -d '\n'
printf "</title>\n <id>$global_url${i#'./'}</id>\n"
printf " <link rel='alternate' href='$global_url${i#'./'}'/>\n <updated>"
echo "$i" | perl -ne '/^(\d{4}-\d{2}-\d{2}).*/; print $1' | date "$date_format_8601" -f - | tr -d '\n'
printf "</updated>\n <summary>You need a gemini protocol client to view this post.&lt;br&gt;If you have one installed, click here to open the post: &lt;a href=\"$global_url${i#'./'}\"&gt;$global_url${i#'./'}&lt;/a&gt;</summary>\n </entry>\n"
n=$(( n + 1 ))
done < <(ls -r ./[[:digit:]]*.gmi)
done < <(ls -r [[:digit:]]*.gmi)
echo '</channel></rss>'
} 3>&1 >"$rssfile"
printf '</feed>'
} 3>&1 >"$atomfile"
mv "$rssfile" "$gemlog_feed"
mv "$atomfile" "$gemlog_feed"
chmod 644 "$gemlog_feed"
}
@ -123,7 +133,7 @@ toot() {
}
make_globals
make_rss
make_atom
build_entries
toot