Skip to content

Commit 6a77334

Browse files
vbfoxepage
authored andcommitted
feat: Expose document categories as a single rss category
An RSS category can be hierarchical by separating the individual parts with a forward slash. https://www.rssboard.org/rss-specification#ltcategorygtSubelementOfLtitemgt
1 parent 8618934 commit 6a77334

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/document.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,24 @@ impl Document {
7979
.permalink(true)
8080
.build();
8181

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+
8293
let item = rss::ItemBuilder::default()
8394
.title(Some(self.front.title.as_str().to_owned()))
8495
.link(Some(link))
8596
.guid(Some(guid))
8697
.pub_date(self.front.published_date.map(|date| date.to_rfc2822()))
8798
.description(self.description_to_str())
88-
.categories(
89-
self.front
90-
.tags
91-
.iter()
92-
.map(|c| Category::from(c.as_str()))
93-
.collect::<Vec<_>>(),
94-
)
99+
.categories(categories)
95100
.build();
96101
Ok(item)
97102
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?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>
22
]]></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>
33
]]></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><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><guid>http://example.com/posts/my-second-blogpost.html</guid><pubDate>Fri, 02 Jan 2015 10:00:00 +0100</pubDate></item></channel></rss>
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)