use crate::{get_articles, html::escape, Args, ArticleMeta, BLOG_BASE};
use std::process::{Command, Stdio};
pub fn generate_atom(args: &Args) -> String {
let entries = get_articles(&args.root.as_ref().unwrap())
.iter()
.map(
|ArticleMeta {
title,
date,
canonical_name,
..
}| {
let title = escape(title);
let datetime = iso8601::DateTime {
date: date.clone(),
time: iso8601::Time {
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
tz_offset_hours: 0,
tz_offset_minutes: 0,
},
};
format!(
r#"
{title}
tag:metamuffin.org,{date},{title}
{datetime}
N/A
metamuffin
metamuffin@disroot.org
"#
)
},
)
.collect::>();
format!(
r#"
metamuffin's blog
where they post pointless stuff
urn:uuid:3cf2b704-3d94-4f1f-b194-42798ab5b47c
{}
metamuffin
metamuffin@disroot.org
{}
"#,
now_rfc3339(),
entries.join("\n")
)
}
fn now_rfc3339() -> String {
String::from_utf8(
Command::new("/usr/bin/date")
.arg("--iso-8601=minutes")
.stdout(Stdio::piped())
.output()
.unwrap()
.stdout,
)
.unwrap()
}