Follow atom_syndication API change

This commit is contained in:
Kitaiti Makoto 2022-01-16 12:02:12 +09:00
parent d253f1a020
commit ba29c8ef6f

View File

@ -3,7 +3,7 @@ use crate::template_utils::Ructe;
use atom_syndication::{ use atom_syndication::{
ContentBuilder, Entry, EntryBuilder, Feed, FeedBuilder, LinkBuilder, Person, PersonBuilder, ContentBuilder, Entry, EntryBuilder, Feed, FeedBuilder, LinkBuilder, Person, PersonBuilder,
}; };
use chrono::naive::NaiveDateTime; use chrono::{naive::NaiveDateTime, DateTime, Utc};
use plume_models::{posts::Post, Connection, CONFIG, ITEMS_PER_PAGE}; use plume_models::{posts::Post, Connection, CONFIG, ITEMS_PER_PAGE};
use rocket::{ use rocket::{
http::{ http::{
@ -134,7 +134,7 @@ pub fn build_atom_feed(
FeedBuilder::default() FeedBuilder::default()
.title(title) .title(title)
.id(uri) .id(uri)
.updated(updated.format("%Y-%m-%dT%H:%M:%SZ").to_string()) .updated(DateTime::<Utc>::from_utc(*updated, Utc))
.entries( .entries(
entries entries
.into_iter() .into_iter()
@ -145,22 +145,18 @@ pub fn build_atom_feed(
.href(uri) .href(uri)
.rel("self") .rel("self")
.mime_type("application/atom+xml".to_string()) .mime_type("application/atom+xml".to_string())
.build() .build()])
.expect("Atom feed: link error")])
.build() .build()
.expect("user::atom_feed: Error building Atom feed")
} }
fn post_to_atom(post: Post, conn: &Connection) -> Entry { fn post_to_atom(post: Post, conn: &Connection) -> Entry {
let formatted_creation_date = post.creation_date.format("%Y-%m-%dT%H:%M:%SZ").to_string();
EntryBuilder::default() EntryBuilder::default()
.title(format!("<![CDATA[{}]]>", post.title)) .title(format!("<![CDATA[{}]]>", post.title))
.content( .content(
ContentBuilder::default() ContentBuilder::default()
.value(format!("<![CDATA[{}]]>", *post.content.get())) .value(format!("<![CDATA[{}]]>", *post.content.get()))
.content_type("html".to_string()) .content_type("html".to_string())
.build() .build(),
.expect("Atom feed: content error"),
) )
.authors( .authors(
post.get_authors(&*conn) post.get_authors(&*conn)
@ -171,21 +167,18 @@ fn post_to_atom(post: Post, conn: &Connection) -> Entry {
.name(a.display_name) .name(a.display_name)
.uri(a.ap_url) .uri(a.ap_url)
.build() .build()
.expect("Atom feed: author error")
}) })
.collect::<Vec<Person>>(), .collect::<Vec<Person>>(),
) )
// Using RFC 4287 format, see https://tools.ietf.org/html/rfc4287#section-3.3 for dates // Using RFC 4287 format, see https://tools.ietf.org/html/rfc4287#section-3.3 for dates
// eg: 2003-12-13T18:30:02Z (Z is here because there is no timezone support with the NaiveDateTime crate) // eg: 2003-12-13T18:30:02Z (Z is here because there is no timezone support with the NaiveDateTime crate)
.published(formatted_creation_date.clone()) .published(Some(
.updated(formatted_creation_date) DateTime::<Utc>::from_utc(post.creation_date, Utc).into(),
))
.updated(DateTime::<Utc>::from_utc(post.creation_date, Utc))
.id(post.ap_url.clone()) .id(post.ap_url.clone())
.links(vec![LinkBuilder::default() .links(vec![LinkBuilder::default().href(post.ap_url).build()])
.href(post.ap_url)
.build()
.expect("Atom feed: link error")])
.build() .build()
.expect("Atom feed: entry error")
} }
pub mod blogs; pub mod blogs;