Browse Source

Improve RSS feed

Improve RSS feed, adding sitemap and markup.
pull/9/head
Danang Probo Sayekti 12 years ago
parent
commit
bd66a69ad5
5 changed files with 39 additions and 5 deletions
  1. +2
    -0
      robots.txt
  2. +8
    -0
      system/htmly.php
  3. +25
    -1
      system/includes/functions.php
  4. +2
    -2
      themes/clean/layout.html.php
  5. +2
    -2
      themes/default/layout.html.php

+ 2
- 0
robots.txt View File

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

+ 8
- 0
system/htmly.php 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


+ 25
- 1
system/includes/functions.php 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);
}


+ 2
- 2
themes/clean/layout.html.php 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>


+ 2
- 2
themes/default/layout.html.php 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>


Loading…
Cancel
Save