use super::{ helper::{get_articles, ArticleMeta}, rocket_uri_macro_r_blog_article, rocket_uri_macro_r_blog_index, ARTICLE_ROOT, }; use crate::{error::MyResult, uri}; use rocket::get; use std::{path::PathBuf, str::FromStr}; #[get("/blog/feed.atom")] pub async fn r_blog_atom() -> MyResult { let entries = get_articles(&PathBuf::from_str(ARTICLE_ROOT).unwrap()) .await? .iter() .map( |ArticleMeta { title, date, canonical_name, .. }| { let title = horrible_escape_function(title); let datetime = iso8601::DateTime { date: date.clone(), time: iso8601::Time::default(), }; let href = uri!(r_blog_article(canonical_name)); format!( r#" {title} tag:metamuffin.org,{date},{title} {datetime} N/A metamuffin metamuffin@disroot.org "# ) }, ) .collect::>(); let feed_url = uri!(r_blog_atom()); let index_url = uri!(r_blog_index()); let now = chrono::Utc::now().to_rfc3339(); Ok(format!( r#" metamuffin's blog where they post pointless stuff urn:uuid:3cf2b704-3d94-4f1f-b194-42798ab5b47c {now} metamuffin metamuffin@disroot.org {} "#, entries.join("\n") )) } pub fn horrible_escape_function(text: &str) -> String { text.replace("&", "&") .replace("<", "<") .replace(">", ">") .replace("'", "’") .replace("\"", """) }