diff options
author | cel 🌸 <cel@blos.sm> | 2023-06-22 21:37:10 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-06-22 21:37:10 +0100 |
commit | ab529917847641190f21129804bbda1784b4f998 (patch) | |
tree | dfdd39286d330dd62339ade0499471b70187ae04 /src/posts/syndication.rs | |
parent | bc5ac494c6162743810b9aeb1cda4f22d94a486a (diff) | |
download | blossom-ab529917847641190f21129804bbda1784b4f998.tar.gz blossom-ab529917847641190f21129804bbda1784b4f998.tar.bz2 blossom-ab529917847641190f21129804bbda1784b4f998.zip |
implement atom syndication
Diffstat (limited to 'src/posts/syndication.rs')
-rw-r--r-- | src/posts/syndication.rs | 96 |
1 files changed, 96 insertions, 0 deletions
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 +} |