-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,66 @@ | ||
use chrono::{DateTime, FixedOffset}; | ||
use serde::Serialize; | ||
|
||
#[derive(Debug, Serialize)] | ||
#[derive(Debug, Serialize, Default)] | ||
pub struct FeedPreview { | ||
pub title: String, | ||
pub link: String, | ||
pub description: Option<String>, | ||
pub posts: Vec<PostPreview>, | ||
} | ||
|
||
#[derive(Debug, Serialize, PartialEq, Eq, Hash)] | ||
#[derive(Debug, Serialize, PartialEq, Eq, Hash, Default)] | ||
pub struct PostPreview { | ||
pub title: String, | ||
pub author: Option<String>, | ||
pub link: String, | ||
pub body: Option<String>, | ||
pub date: Option<DateTime<FixedOffset>>, | ||
} | ||
|
||
impl PostPreview { | ||
pub fn into_rss_item(self) -> rss::Item { | ||
let guid = rss::Guid { | ||
value: self.link.clone(), | ||
permalink: true, | ||
}; | ||
|
||
rss::Item { | ||
title: Some(self.title), | ||
link: Some(self.link), | ||
description: self.body, | ||
pub_date: self.date.map(|d| d.to_rfc3339()), | ||
author: self.author, | ||
guid: Some(guid), | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn into_atom_entry(self) -> atom_syndication::Entry { | ||
atom_syndication::Entry { | ||
title: atom_syndication::Text::plain(self.title), | ||
id: self.link.clone(), | ||
links: vec![atom_syndication::Link { | ||
href: self.link, | ||
..Default::default() | ||
}], | ||
authors: self | ||
.author | ||
.into_iter() | ||
.map(|a| atom_syndication::Person { | ||
name: a, | ||
..Default::default() | ||
}) | ||
.collect(), | ||
updated: self | ||
.date | ||
.unwrap_or_else(|| chrono::Utc::now().fixed_offset()), | ||
published: self.date, | ||
content: self.body.map(|b| atom_syndication::Content { | ||
value: Some(b), | ||
..Default::default() | ||
}), | ||
..Default::default() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters