Use content as description in RSS items

This commit is contained in:
Stas Rudakou 2016-10-23 01:27:03 +03:00
parent bd120ee796
commit fa93df81fb
3 changed files with 24 additions and 10 deletions

View file

@ -122,11 +122,6 @@ pub fn build(config: &Config) -> Result<()> {
// fall back to the default date
posts.sort_by(|a, b| b.date.unwrap_or(default_date).cmp(&a.date.unwrap_or(default_date)));
// check if we should create an RSS file and create it!
if let &Some(ref path) = &config.rss {
try!(create_rss(path, dest, &config, &posts));
}
// collect all posts attributes to pass them to other posts for rendering
let simple_posts_data: Vec<Value> = posts.iter()
.map(|x| Value::Object(x.attributes.clone()))
@ -143,6 +138,11 @@ pub fn build(config: &Config) -> Result<()> {
try!(create_document_file(&post_html, &post.path, dest));
}
// check if we should create an RSS file and create it!
if let &Some(ref path) = &config.rss {
try!(create_rss(path, dest, &config, &posts));
}
// during post rendering additional attributes such as content were
// added to posts. collect them so that non-post documents can access them
let posts_data: Vec<Value> = posts.into_iter()

View file

@ -220,15 +220,17 @@ impl Document {
/// Metadata for generating RSS feeds
pub fn to_rss(&self, root_url: &str) -> rss::Item {
let description = self.attributes.get("description")
.or(self.attributes.get("content"))
.and_then(|s| s.as_str())
.map(|s| s.to_owned());
rss::Item {
title: self.attributes.get("title").and_then(|s| s.as_str()).map(|s| s.to_owned()),
// Swap back slashes to forward slashes to ensure the URL's are valid on Windows
link: Some(root_url.to_owned() + &self.path.replace("\\", "/")),
pub_date: self.date.map(|date| date.to_rfc2822()),
description: self.attributes
.get("description")
.and_then(|s| s.as_str())
.map(|s| s.to_owned()),
description: description,
..Default::default()
}
}

View file

@ -1 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?><rss version='2.0'><channel><title>My blog!</title><link>http://example.com/</link><description>Blog description</description><item><title>My fifth Blogpost!</title><link>http://example.com/posts/my-fifth-blogpost.html</link><pubDate>Tue, 16 Feb 2016 10:00:00 +0100</pubDate></item><item><title>My first Blogpost</title><link>http://example.com/posts/my-first-blogpost.html</link><description>It&apos;s my first blog post</description><pubDate>Fri, 1 Jan 2016 21:00:00 +0100</pubDate></item><item><title>My fourth Blogpost</title><link>http://example.com/posts/my-fourth-blogpost.html</link><pubDate>Fri, 29 May 2015 23:00:00 +0100</pubDate></item><item><title>My third Blogpost</title><link>http://example.com/posts/my-third-blogpost.html</link><pubDate>Wed, 27 May 2015 23:00:00 +0100</pubDate></item><item><title>My second Blogpost</title><link>http://example.com/posts/my-second-blogpost.html</link><pubDate>Fri, 2 Jan 2015 10:00:00 +0100</pubDate></item></channel></rss>
<?xml version='1.0' encoding='UTF-8'?><rss version='2.0'><channel><title>My blog!</title><link>http://example.com/</link><description>Blog description</description><item><title>My fifth Blogpost!</title><link>http://example.com/posts/my-fifth-blogpost.html</link><description>&lt;h1&gt;My fifth Blogpost!&lt;/h1&gt;
&lt;p&gt;Hey there this is my first blogpost and this is super awesome.&lt;/p&gt;
&lt;p&gt;My Blog is lorem ipsum like, yes it is..&lt;/p&gt;
</description><pubDate>Tue, 16 Feb 2016 10:00:00 +0100</pubDate></item><item><title>My first Blogpost</title><link>http://example.com/posts/my-first-blogpost.html</link><description>It&apos;s my first blog post</description><pubDate>Fri, 1 Jan 2016 21:00:00 +0100</pubDate></item><item><title>My fourth Blogpost</title><link>http://example.com/posts/my-fourth-blogpost.html</link><description>&lt;h1&gt;My fourth Blogpost&lt;/h1&gt;
&lt;p&gt;Hey there this is my first blogpost and this is super awesome.&lt;/p&gt;
&lt;p&gt;My Blog is lorem ipsum like, yes it is..&lt;/p&gt;
</description><pubDate>Fri, 29 May 2015 23:00:00 +0100</pubDate></item><item><title>My third Blogpost</title><link>http://example.com/posts/my-third-blogpost.html</link><description>&lt;h1&gt;My third Blogpost&lt;/h1&gt;
&lt;p&gt;Hey there this is my first blogpost and this is super awesome.&lt;/p&gt;
&lt;p&gt;My Blog is lorem ipsum like, yes it is..&lt;/p&gt;
</description><pubDate>Wed, 27 May 2015 23:00:00 +0100</pubDate></item><item><title>My second Blogpost</title><link>http://example.com/posts/my-second-blogpost.html</link><description>&lt;h1&gt;My second Blogpost&lt;/h1&gt;
&lt;p&gt;Hey there this is my first blogpost and this is super awesome.&lt;/p&gt;
&lt;p&gt;My Blog is lorem ipsum like, yes it is..&lt;/p&gt;
</description><pubDate>Fri, 2 Jan 2015 10:00:00 +0100</pubDate></item></channel></rss>