<?php
require __DIR__ . '/posts.php';

$siteUrl   = 'https://hexstudios.co';
$siteTitle = 'Hex Studios';
$siteDesc  = 'Developer, biker, musician, engineer, and an unapologetic centrist in the deep red south.';

$posts = getPosts(__DIR__);

function xmlEscape($str) {
    return htmlspecialchars($str, ENT_XML1 | ENT_QUOTES, 'UTF-8');
}

header('Content-Type: application/rss+xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<rss version="2.0">
    <channel>
        <title><?= xmlEscape($siteTitle) ?></title>
        <link><?= xmlEscape($siteUrl) ?></link>
        <description><?= xmlEscape($siteDesc) ?></description>
        <language>en-us</language>
        <lastBuildDate><?= date(DATE_RSS) ?></lastBuildDate>
        <?php foreach ($posts as $post):
            $postUrl = $post['type'] === 'html'
                ? $siteUrl . '/posts/' . $post['file']
                : $siteUrl . '/post.html?file=' . urlencode($post['file']);
        ?>
        <item>
            <title><?= xmlEscape($post['title']) ?></title>
            <link><?= xmlEscape($postUrl) ?></link>
            <guid isPermaLink="true"><?= xmlEscape($postUrl) ?></guid>
            <pubDate><?= date(DATE_RSS, $post['created']) ?></pubDate>
            <description><?= xmlEscape($post['excerpt']) ?></description>
            <?php foreach ($post['tags'] as $tag): ?>
                <category><?= xmlEscape($tag) ?></category>
            <?php endforeach; ?>
        </item>
        <?php endforeach; ?>
    </channel>
</rss>