<?php
require 'db.php';

header("Content-Type: application/rss+xml; charset=UTF-8");

$base = "https://spawnpy.com/experiments/articles/";

$rows = $pdo->query("
SELECT slug,title,excerpt,published_at
FROM articles
ORDER BY published_at DESC
LIMIT 30
")->fetchAll();

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<rss version="2.0">
<channel>
<title>SpawnPy Articles</title>
<link><?= $base ?></link>
<description>Latest tech articles</description>

<?php foreach($rows as $r): ?>
<item>
<title><?= htmlspecialchars($r['title']) ?></title>
<link><?= $base.$r['slug'] ?></link>
<description><?= htmlspecialchars($r['excerpt']) ?></description>
<pubDate><?= date(DATE_RSS,strtotime($r['published_at'])) ?></pubDate>
</item>
<?php endforeach; ?>

</channel>
</rss>
