Improve RSS feed

Improve RSS feed, adding sitemap and markup.
This commit is contained in:
Danang Probo Sayekti 2014-01-14 19:21:06 +07:00
commit bd66a69ad5
5 changed files with 39 additions and 5 deletions

View file

@ -30,3 +30,5 @@ Disallow: /composer.lock
Disallow: /composer.phar
# Paths
Disallow: /search/
Sitemap: /feed/sitemap

View file

@ -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

View file

@ -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);
}

View file

@ -16,8 +16,8 @@
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="<?php echo $bodyclass; ?>">
<div itemscope="itemscope" itemtype="http://schema.org/Blog" class="hide">
<body class="<?php echo $bodyclass; ?>" itemscope="itemscope" itemtype="http://schema.org/Blog">
<div class="hide">
<meta content="<?php echo config('blog.title') ?>" itemprop="name"/>
<meta content="<?php echo config('blog.description')?>" itemprop="description"/>
</div>

View file

@ -16,8 +16,8 @@
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="<?php echo $bodyclass; ?>">
<div itemscope="itemscope" itemtype="http://schema.org/Blog" class="hide">
<body class="<?php echo $bodyclass; ?>" itemscope="itemscope" itemtype="http://schema.org/Blog">
<div class="hide">
<meta content="<?php echo config('blog.title') ?>" itemprop="name"/>
<meta content="<?php echo config('blog.description')?>" itemprop="description"/>
</div>