#!/bin/zsh
title="Tilde Whirl Tildeverse Podcast"
author="dozens"
email="dozens@tilde.team"
description="the greatest tildeverse podcast in the world"
baseurl="https://tilde.town/~dozens/podcast"
link="$baseurl/index.html"
href="$baseurl/rss.xml"
img_url="$baseurl/assets/img/logo.png"
outfile="dist/rss.xml"


echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>" > $outfile
echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">" >> $outfile
echo "<channel><title>$title</title>" >> $outfile
echo "<link>$link</link><description>$description</description>" >> $outfile
echo "<atom:link rel=\"self\" type=\"application/rss+xml\" href=\"$href\"/>" >> $outfile
echo "<image>" >> $outfile
echo "  <url>$img_url</url>" >> $outfile
echo "  <title>$title</title>" >> $outfile
echo "  <link>$link</link>" >> $outfile
echo "</image>" >> $outfile
echo "<generator>pandoc and stuff</generator>" >> $outfile
echo "<lastBuildDate>$(gdate -R)</lastBuildDate>" >> $outfile
echo "<atom:link href=\"$href\" rel=\"self\" type=\"application/rss+xml\"/>" >> $outfile
echo "<webMaster>$email (dozens)</webMaster>" >> $outfile
echo "<managingEditor>$email (dozens)</managingEditor>" >> $outfile
echo "<copyright>$author</copyright>" >> $outfile
echo "<language>en</language>" >> $outfile

for file in $(ls -1 content/*.md | sort -r)
do
  dest="${$(basename $file)/md/html}"
  pandoc --template=templates/podcast-feed-item.template \
    --variable=url:"$baseurl/$dest" $file \
    >> $outfile
done

echo '</channel></rss>' >> $outfile

