Skip to content

Commit 493d893

Browse files
authored
Merge pull request #1258 from vbfox/tags_as_categories
feat: Expose tags as categories in rss
2 parents 6dd1135 + 6a77334 commit 493d893

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed

src/document.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use liquid::ValueView;
1010
use liquid::model::Value;
1111
use log::trace;
1212
use regex::Regex;
13+
use rss::Category;
1314

1415
use crate::cobalt_model;
1516
use crate::cobalt_model::Minify;
@@ -78,12 +79,24 @@ impl Document {
7879
.permalink(true)
7980
.build();
8081

82+
let mut categories = self
83+
.front
84+
.tags
85+
.iter()
86+
.map(|c| Category::from(c.as_str()))
87+
.collect::<Vec<_>>();
88+
89+
if !self.front.categories.is_empty() {
90+
categories.push(self.front.categories.join("/").into());
91+
}
92+
8193
let item = rss::ItemBuilder::default()
8294
.title(Some(self.front.title.as_str().to_owned()))
8395
.link(Some(link))
8496
.guid(Some(guid))
8597
.pub_date(self.front.published_date.map(|date| date.to_rfc2822()))
8698
.description(self.description_to_str())
99+
.categories(categories)
87100
.build();
88101
Ok(item)
89102
}

tests/cmd/rss.in/posts/my-first-blogpost.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ layout: posts.liquid
44
title: My first Blogpost
55
description: It's my first blog post
66
published_date: 2016-01-01 21:00:00 +0100
7+
tags: [blog, first]
78
---
89
# {{ page.title }}
910

tests/cmd/rss.in/posts/my-second-blogpost.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ layout: posts.liquid
33

44
title: My second Blogpost
55
published_date: 2015-01-02 10:00:00 +0100
6+
categories: [lorem, ipsum]
67
---
78
# {{ page.title }}
89

tests/cmd/rss.in/posts/my-third-blogpost.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ layout: posts.liquid
33

44
title: My third Blogpost
55
published_date: 2015-05-27 23:00:00 +0100
6+
tags: [test, blogpost]
7+
categories: [blog, test]
68
---
79
# {{ page.title }}
810

tests/cmd/rss.out/_dest/.keep

Whitespace-only changes.

tests/cmd/rss.out/_dest/rss.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?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><![CDATA[<h1>My fifth Blogpost!</h1>
2+
]]></description><guid>http://example.com/posts/my-fifth-blogpost.html</guid><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><![CDATA[It's my first blog post]]></description><category>blog</category><category>first</category><guid>http://example.com/posts/my-first-blogpost.html</guid><pubDate>Fri, 01 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><![CDATA[<h1>My fourth Blogpost</h1>
3+
]]></description><guid>http://example.com/posts/my-fourth-blogpost.html</guid><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><![CDATA[<h1>My third Blogpost</h1>
4+
]]></description><category>test</category><category>blogpost</category><category>blog/test</category><guid>http://example.com/posts/my-third-blogpost.html</guid><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><![CDATA[<h1>My second Blogpost</h1>
5+
]]></description><category>lorem/ipsum</category><guid>http://example.com/posts/my-second-blogpost.html</guid><pubDate>Fri, 02 Jan 2015 10:00:00 +0100</pubDate></item></channel></rss>

0 commit comments

Comments
 (0)