mirror of
https://github.com/cobalt-org/cobalt.rs
synced 2024-11-15 00:17:29 +00:00
Use content as description in RSS items
This commit is contained in:
parent
bd120ee796
commit
fa93df81fb
3 changed files with 24 additions and 10 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'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><h1>My fifth Blogpost!</h1>
|
||||
<p>Hey there this is my first blogpost and this is super awesome.</p>
|
||||
<p>My Blog is lorem ipsum like, yes it is..</p>
|
||||
</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'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><h1>My fourth Blogpost</h1>
|
||||
<p>Hey there this is my first blogpost and this is super awesome.</p>
|
||||
<p>My Blog is lorem ipsum like, yes it is..</p>
|
||||
</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><h1>My third Blogpost</h1>
|
||||
<p>Hey there this is my first blogpost and this is super awesome.</p>
|
||||
<p>My Blog is lorem ipsum like, yes it is..</p>
|
||||
</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><h1>My second Blogpost</h1>
|
||||
<p>Hey there this is my first blogpost and this is super awesome.</p>
|
||||
<p>My Blog is lorem ipsum like, yes it is..</p>
|
||||
</description><pubDate>Fri, 2 Jan 2015 10:00:00 +0100</pubDate></item></channel></rss>
|
Loading…
Reference in a new issue