Skip to content

Commit 8618934

Browse files
vbfoxepage
authored andcommitted
feat: Expose document tags as rss categories
Add to the rss feed one <cateogry /> per tag of the document. https://www.rssboard.org/rss-specification#ltcategorygtSubelementOfLtitemgt
1 parent 2a049f7 commit 8618934

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/document.rs

Lines changed: 8 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;
@@ -84,6 +85,13 @@ impl Document {
8485
.guid(Some(guid))
8586
.pub_date(self.front.published_date.map(|date| date.to_rfc2822()))
8687
.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+
)
8795
.build();
8896
Ok(item)
8997
}

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>
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><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>
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>
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><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>
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>
55
]]></description><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)