#!/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 "<rss version=\"2.0\"><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>$(date)</lastBuildDate>" >> $outfile
echo "<atom:link href=\"$href\" rel=\"self\" type=\"application/rss+xml\"/>" >> $outfile
echo "<author>$author</author>" >> $outfile
echo "<copyright>$author</copyright>" >> $outfile
echo "<language>en</language>" >> $outfile
echo "<itunes:author>$author</itunes:author>" >> $outfile
echo "<itunes:summary>$description</itunes:summary>" >> $outfile
echo "<itunes:type>episodic</itunes:type>" >> $outfile
echo "<itunes:owner>" >> $outfile
echo "  <itunes:name>$author</itunes:name>" >> $outfile
echo "  <itunes:email>$email</itunes:email>" >> $outfile
echo "</itunes:owner>" >> $outfile
echo "<itunes:explicit>No</itunes:explicit>" >> $outfile
echo "<itunes:category text=\"Technology\">" >> $outfile
echo "</itunes:category>" >> $outfile
echo "<itunes:image href=\"$img_url\"/>" >> $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

