diff options
Diffstat (limited to '')
-rw-r--r-- | src/posts/mod.rs | 1 | ||||
-rw-r--r-- | src/posts/syndication.rs | 96 |
2 files changed, 97 insertions, 0 deletions
diff --git a/src/posts/mod.rs b/src/posts/mod.rs index 2dc5c4b..7f8e6c4 100644 --- a/src/posts/mod.rs +++ b/src/posts/mod.rs @@ -1,5 +1,6 @@ mod article; mod note; +pub mod syndication; use std::collections::HashSet; diff --git a/src/posts/syndication.rs b/src/posts/syndication.rs new file mode 100644 index 0000000..f6f0b17 --- /dev/null +++ b/src/posts/syndication.rs @@ -0,0 +1,96 @@ +use atom_syndication::{Category, Content, Entry, Feed, Generator, Link, Person, Text, TextType}; + +use super::{Article, Post}; + +pub async fn atom(posts: Vec<Post<Article>>) -> Feed { + let me = Person { + name: "cel".into(), + email: Some("cel@blos.sm".into()), + uri: Some("https://blos.sm".into()), + }; + let mut authors = Vec::new(); + authors.push(me); + let link = Link { + href: "https://blos.sm/feed".into(), + rel: "self".into(), + hreflang: Some("en".into()), + mime_type: Some("application/atom+xml".into()), + title: Some("atom feed".into()), + length: None, + }; + let mut links = Vec::new(); + links.push(link); + let mut feed = Feed { + title: Text { + value: "cel's site".into(), + base: None, + lang: Some("en".into()), + r#type: TextType::Text, + }, + id: "https://blos.sm".into(), + updated: posts[0].created_at.into(), + authors: authors.clone(), + categories: Vec::new(), + contributors: authors.clone(), + generator: Some(Generator { + value: "blos.sm".into(), + uri: Some("https://bunny.garden/cel/blos.sm".into()), + version: None, + }), + icon: Some("/icon.png".into()), + links: links.clone(), + logo: Some("/logo.png".into()), + rights: None, + subtitle: None, + entries: Vec::new(), + base: Some("https://blos.sm".into()), + lang: Some("en".into()), + ..Default::default() + }; + for mut post in posts { + post.render().await.unwrap_or_default(); + let mut id = String::from("https://blos.sm/blog/"); + id.push_str(&post.data.name); + let categories = post + .tags + .into_iter() + .map(|tag| Category { + term: tag.clone(), + scheme: None, + label: Some(tag.clone()), + }) + .collect(); + let entry = Entry { + title: Text { + value: post.subject.unwrap_or_default(), + base: None, + lang: Some("en".into()), + r#type: TextType::Text, + }, + id: id.clone(), + updated: if let Some(updated_at) = post.updated_at { + updated_at.into() + } else { + post.created_at.into() + }, + authors: authors.clone(), + categories, + contributors: authors.clone(), + links: links.clone(), + published: Some(post.created_at.into()), + rights: None, + source: None, + summary: None, + content: Some(Content { + base: None, + lang: Some("en".into()), + value: post.render, + src: Some(id), + content_type: Some("html".to_string()), + }), + ..Default::default() + }; + feed.entries.push(entry); + } + feed +} |