feat: add RSS and Atom feeds with caching and nice links

This commit is contained in:
David Bailey 2023-12-25 20:13:00 +01:00
parent c6297fd81b
commit 596cc0e1a3
7 changed files with 120 additions and 1 deletions

View file

@ -111,6 +111,14 @@ function generate_website($SURI) {
echo $twig->render('upload.html');
}
} elseif(preg_match('/^\/feed(?:\/(rss|atom)(.*))?$/', $SURI, $match)) {
$feed = $adapter->get_laminas_feed($match[2] ?? '/', $match[1] ?? 'rss');
header('Content-Type: application/xml');
header('Cache-Control: max-age=1800');
header('Etag: W/"' . $SURI . '/' . strtotime($feed['feed_ts']) . '"');
echo $feed['feed'];
} elseif(preg_match('/^\s*image/', $_SERVER['HTTP_ACCEPT'])) {
header('Location: /raw' . $SURI);
exit(0);