diff options
author | metamuffin <metamuffin@disroot.org> | 2022-08-29 22:53:37 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-08-29 22:53:37 +0200 |
commit | 3eb1adfeb8dd477479404a1269c8682e3b4edf12 (patch) | |
tree | 1a4788149dc4b958dee129c28b95553cc3927f16 /code/src/atom.rs | |
parent | a4dd9c4944340505962f07853d53ab02f3a02336 (diff) | |
download | metamuffin-blog-3eb1adfeb8dd477479404a1269c8682e3b4edf12.tar metamuffin-blog-3eb1adfeb8dd477479404a1269c8682e3b4edf12.tar.bz2 metamuffin-blog-3eb1adfeb8dd477479404a1269c8682e3b4edf12.tar.zst |
split files
Diffstat (limited to 'code/src/atom.rs')
-rw-r--r-- | code/src/atom.rs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/code/src/atom.rs b/code/src/atom.rs new file mode 100644 index 0000000..4c6a771 --- /dev/null +++ b/code/src/atom.rs @@ -0,0 +1,73 @@ +use crate::{get_articles, 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, + filename, + .. + }| { + 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#" + <entry> + <title>{title}</title> + <link href="https://{BLOG_BASE}/{filename}.html" /> + <id>tag:metamuffin.org,{date},{title}</id> + <published>{datetime}</published> + <summary>N/A</summary> + <author> + <name>metamuffin</name> + <email>metamuffin@disroot.org</email> + </author> + </entry>"# + ) + }, + ) + .collect::<Vec<_>>(); + format!( + r#"<?xml version="1.0" encoding="utf-8"?> + <feed xmlns="http://www.w3.org/2005/Atom"> + <title>metamuffin's blog</title> + <subtitle>where they post pointless stuff</subtitle> + <link href="https://{BLOG_BASE}/feed.atom" rel="self" /> + <link href="https://{BLOG_BASE}/" /> + <id>urn:uuid:3cf2b704-3d94-4f1f-b194-42798ab5b47c</id> + <updated>{}</updated> + <author> + <name>metamuffin</name> + <email>metamuffin@disroot.org</email> + </author> + {} + </feed> + "#, + 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() +} |