fix RSS/Atom/JSONFeed validation errors

This commit is contained in:
Cadey Ratio 2020-07-14 21:52:41 -04:00
parent 16d17f3222
commit 3f4455d43a
4 changed files with 27 additions and 5 deletions

2
Cargo.lock generated
View File

@ -876,7 +876,7 @@ dependencies = [
[[package]] [[package]]
name = "jsonfeed" name = "jsonfeed"
version = "0.2.0" version = "0.3.0"
dependencies = [ dependencies = [
"error-chain", "error-chain",
"serde", "serde",

View File

@ -1,12 +1,12 @@
[package] [package]
authors = ["Paul Woolcock <paul@woolcock.us>"] authors = ["Paul Woolcock <paul@woolcock.us>", "Christine Dodrill <me@christine.website>"]
description = "Parser for the JSONFeed (http://jsonfeed.org) specification\n" description = "Parser for the JSONFeed (http://jsonfeed.org) specification\n"
documentation = "https://docs.rs/jsonfeed" documentation = "https://docs.rs/jsonfeed"
homepage = "https://github.com/pwoolcoc/jsonfeed" homepage = "https://github.com/pwoolcoc/jsonfeed"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
name = "jsonfeed" name = "jsonfeed"
readme = "README.adoc" readme = "README.adoc"
version = "0.2.0" version = "0.3.0"
[dependencies] [dependencies]
error-chain = "0.12" error-chain = "0.12"

View File

@ -151,6 +151,11 @@ impl ItemBuilder {
self self
} }
pub fn author(mut self, who: Author) -> ItemBuilder {
self.author = Some(who);
self
}
pub fn content_html<I: Into<String>>(mut self, i: I) -> ItemBuilder { pub fn content_html<I: Into<String>>(mut self, i: I) -> ItemBuilder {
match self.content { match self.content {
Some(Content::Text(t)) => { Some(Content::Text(t)) => {

View File

@ -20,9 +20,16 @@ impl Into<jsonfeed::Item> for Post {
let mut result = jsonfeed::Item::builder() let mut result = jsonfeed::Item::builder()
.title(self.front_matter.title) .title(self.front_matter.title)
.content_html(self.body_html) .content_html(self.body_html)
.content_text(self.body)
.id(format!("https://christine.website/{}", self.link)) .id(format!("https://christine.website/{}", self.link))
.url(format!("https://christine.website/{}", self.link)) .url(format!("https://christine.website/{}", self.link))
.date_published(self.date.to_rfc3339()); .date_published(self.date.to_rfc3339())
.author(
jsonfeed::Author::new()
.name("Christine Dodrill")
.url("https://christine.website")
.avatar("https://christine.website/static/img/avatar.png"),
);
let mut tags: Vec<String> = vec![]; let mut tags: Vec<String> = vec![];
@ -57,6 +64,16 @@ impl Into<atom::Entry> for Post {
let content = content.build().unwrap(); let content = content.build().unwrap();
let mut result = atom::EntryBuilder::default(); let mut result = atom::EntryBuilder::default();
result.id(format!("https://christine.website/{}", self.link));
result.contributors({
let mut me = atom::Person::default();
me.set_name("Christine Dodrill");
me.set_email("me@christine.website".to_string());
me.set_uri("https://christine.website".to_string());
vec![me]
});
result.title(self.front_matter.title); result.title(self.front_matter.title);
let mut link = atom::Link::default(); let mut link = atom::Link::default();
link.href = format!("https://christine.website/{}", self.link); link.href = format!("https://christine.website/{}", self.link);
@ -76,7 +93,7 @@ impl Into<rss::Item> for Post {
result.title(Some(self.front_matter.title)); result.title(Some(self.front_matter.title));
result.link(format!("https://christine.website/{}", self.link)); result.link(format!("https://christine.website/{}", self.link));
result.guid(guid); result.guid(guid);
result.author(Some("Christine Dodrill <me@christine.website>".to_string())); result.author(Some("me@christine.website (Christine Dodrill)".to_string()));
result.content(self.body_html); result.content(self.body_html);
result.pub_date(self.date.to_rfc2822()); result.pub_date(self.date.to_rfc2822());