aboutsummaryrefslogtreecommitdiffstats
path: root/src/posts/syndication.rs
blob: f6f0b1704fc6c72330f51ee5b113864ca31410fe (plain) (blame)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
}