#!
SITE_URL="$1"
POSTS="$(ls --reverse "${SRC}/blog/" | grep "^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\(\.[0-9]\+\)\?\.blog.upphtml$")"
NOW_RFC_822="$(TZ=UT date +"%a, %d %b %Y %H:%M:%S UT")"
#!

<rss version='2.0'>

<channel>
<title>Joe Carstairs’ blog</title>
<description>Short posts on random topics I find interesting</description>
<link>${SITE_URL}/blog</link>
<image>${SITE_URL}/images/headshot.webp</image>
<language>en-GB</language>
<pubDate>${NOW_RFC_822}</pubDate>

#!
for post in $POSTS; do
POST_ID="$(echo ${post} | cut -c1-$(( ${#post} - 13 )) )"
. "${SRC}/blog/${post}.args"
DATE_PUBLISHED_RFC_822="$(TZ=UT date --date="$( echo "${POST_ID}" | cut -c1-10)" +"%a, %d %b %Y %H:%M:%S UT")"
#!
<item>

<title>${POST_TITLE}</title>
<link>${SITE_URL}/blog/${POST_ID}</link>
<guid isPermaLink='true'>${SITE_URL}/blog/${POST_ID}</guid>
<pubDate>${DATE_PUBLISHED_RFC_822}</pubDate>
<description>
#!
NO_META=1 pp "${SRC}/blog/$post" "${SITE_URL}" \
  | sed "s/&/\\&amp;/g" \
  | sed "s/</\\&lt;/g" \
  | sed "s/>/\\&gt;/g" \
  | sed "s/\"/\\&quot;/g" \
  | sed "s/'/\\&#x27;/g" \
  | sed "s/\`/\\&#x60;/g" \
  | sed "s/\\\$/\\\\\$/g"
#!
</description>
<author>Joe Carstairs</author>

</item>
#!
done
#!

</channel>

</rss>
