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
|
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<String> {
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#"
<entry>
<title>{title}</title>
<link href="{href}" />
<id>tag:metamuffin.org,{date},{canonical_name}</id>
<published>{datetime}</published>
<summary>N/A</summary>
<author>
<name>metamuffin</name>
<email>metamuffin@disroot.org</email>
</author>
</entry>"#
)
},
)
.collect::<Vec<_>>();
let feed_url = uri!(r_blog_atom());
let index_url = uri!(r_blog_index());
let now = chrono::Utc::now().to_rfc3339();
Ok(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="{feed_url}" rel="self" />
<link href="{index_url}" />
<id>urn:uuid:3cf2b704-3d94-4f1f-b194-42798ab5b47c</id>
<updated>{now}</updated>
<author>
<name>metamuffin</name>
<email>metamuffin@disroot.org</email>
</author>
{}
</feed>
"#,
entries.join("\n")
))
}
pub fn horrible_escape_function(text: &str) -> String {
text.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace("'", "’")
.replace("\"", """)
}
|