aboutsummaryrefslogtreecommitdiff
path: root/code/src/atom.rs
blob: 7912b972ff504f23d7cb601e93ca6e4ccb68827c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::{get_articles, markdown::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#"
                <entry>
                <title>{title}</title>
                <link href="{BLOG_BASE}/{canonical_name}.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="{BLOG_BASE}/feed.atom" rel="self" />
	<link href="{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()
}