From bd66a69ad52adfe0571159794124ec9be1fe9ff0 Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Tue, 14 Jan 2014 19:21:06 +0700 Subject: [PATCH] Improve RSS feed Improve RSS feed, adding sitemap and markup. --- robots.txt | 2 ++ system/htmly.php | 8 ++++++++ system/includes/functions.php | 26 +++++++++++++++++++++++++- themes/clean/layout.html.php | 4 ++-- themes/default/layout.html.php | 4 ++-- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/robots.txt b/robots.txt index 308f4ad..bd761f4 100644 --- a/robots.txt +++ b/robots.txt @@ -30,3 +30,5 @@ Disallow: /composer.lock Disallow: /composer.phar # Paths Disallow: /search/ + +Sitemap: /feed/sitemap \ No newline at end of file diff --git a/system/htmly.php b/system/htmly.php index 31b5c12..e2f4c08 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -270,6 +270,14 @@ get('/feed/rss',function(){ echo generate_rss(get_posts(null, 1, config('rss.count'))); }); +// Show the RSS feed for sitemap +get('/feed/sitemap',function(){ + + header('Content-Type: application/rss+xml'); + + // Generate RSS feed for all blog posts + echo generate_sitemap(get_posts(null, null, null)); +}); // If we get here, it means that // nothing has been matched above diff --git a/system/includes/functions.php b/system/includes/functions.php index f3b7749..1eed207 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -935,12 +935,36 @@ function generate_rss($posts){ ->appendTo($feed); foreach($posts as $p){ - $item = new Item(); $item ->title($p->title) + ->pubDate($p->date) ->description($p->body) ->url($p->url) + ->category($p->tag, $p->tagurl) + ->appendTo($channel); + } + + echo $feed; +} + +// Turn an array of posts into an RSS feed for sitemap +function generate_sitemap($posts){ + + $feed = new Feed(); + $channel = new Channel(); + + $channel + ->title(config('blog.title')) + ->description(config('blog.description')) + ->url(site_url()) + ->appendTo($feed); + + foreach($posts as $p){ + $item = new Item(); + $item + ->title($p->title) + ->url($p->url) ->appendTo($channel); } diff --git a/themes/clean/layout.html.php b/themes/clean/layout.html.php index a109af3..09de1bd 100644 --- a/themes/clean/layout.html.php +++ b/themes/clean/layout.html.php @@ -16,8 +16,8 @@ - -
+ +
diff --git a/themes/default/layout.html.php b/themes/default/layout.html.php index 514248b..1cde94f 100644 --- a/themes/default/layout.html.php +++ b/themes/default/layout.html.php @@ -16,8 +16,8 @@ - -
+ +