From f1496b06538f785b0200e867885a8a08c17b8b35 Mon Sep 17 00:00:00 2001 From: Jannik Beyerstedt Date: Sun, 31 Jan 2021 00:25:42 +0100 Subject: [PATCH] Add RSS feed to blog --- site/snippets/blog-htmlhead.php | 2 ++ site/snippets/blogfeed.php | 33 +++++++++++++++++++++++++++++++++ site/templates/blog.php | 8 ++++++++ 3 files changed, 43 insertions(+) create mode 100644 site/snippets/blogfeed.php diff --git a/site/snippets/blog-htmlhead.php b/site/snippets/blog-htmlhead.php index a6aa516..b6f5e27 100644 --- a/site/snippets/blog-htmlhead.php +++ b/site/snippets/blog-htmlhead.php @@ -26,6 +26,8 @@ if( $page->isHomePage() ) { + + diff --git a/site/snippets/blogfeed.php b/site/snippets/blogfeed.php new file mode 100644 index 0000000..b476599 --- /dev/null +++ b/site/snippets/blogfeed.php @@ -0,0 +1,33 @@ +$articles, "link"=>$baseurl, "feedurl"=>$feedurl]) +// ------------------------------------------- + +header("Content-Type: application/rss+xml"); +?> + + + + Janniks Blog + Persönliches Blog von Jannik Beyerstedt + + + + + + + <?php echo \Kirby\Toolkit\Xml::encode($a->title()) ?> + url()) ?> + jbeyerstedt/slug()) ?> + date()->toDate("d M Y H:i:s O") ?> + text()->kirbytext() ?>]]> + + + + + diff --git a/site/templates/blog.php b/site/templates/blog.php index 1646d9f..8a4ba2f 100644 --- a/site/templates/blog.php +++ b/site/templates/blog.php @@ -25,9 +25,17 @@ function tags_html($base_url, $article) { $base_url = $site->find('blog')->url(); +$feed_url = $base_url.'?rss'; $articles = $page->children()->listed()->flip(); $title = $page->title()->html(); +// Deliver RSS feed on ?rss GET parameter +$is_rss = get('rss'); +if ($is_rss !== null) { + snippet('blogfeed', ["articles"=>$articles,"link"=>$base_url,"feedurl"=>$feed_url]); + exit; +} + // Filter by requested tag if($tag = param('tag')) { $articles = $articles->filterBy('tags', $tag, ',');