diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 40f546d..844f3aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,8 +7,9 @@ mod skweets; use std::borrow::Cow; use std::collections::HashSet; +use atom_syndication::Feed; use rocket::fs::{relative, FileServer}; -use rocket::http::Status; +use rocket::http::{ContentType, Status}; use rocket::{Request, State}; use rocket_dyn_templates::{context, Template}; @@ -87,6 +88,17 @@ async fn blog(filter: Vec<String>) -> Result<Template> { )) } +#[get("/feed")] +async fn feed() -> Result<(Status, (ContentType, String))> { + let posts = posts::get_blogposts().await?; + let feed = posts::syndication::atom(posts).await; + let feed: String = String::from_utf8(feed.write_to(Vec::new())?)?; + Ok(( + Status::new(200), + (ContentType::new("application", "atom+xml"), feed), + )) +} + #[get("/contact")] async fn contact() -> Template { Template::render("contact", context! {}) @@ -130,7 +142,7 @@ async fn main() -> std::result::Result<(), rocket::Error> { .attach(Template::custom(|engines| { engines.tera.autoescape_on(vec![]); })) - .mount("/", routes![home, contact, blog, blogpost, plants]) + .mount("/", routes![home, contact, blog, blogpost, feed, plants]) .register("/", catchers![catcher]) .mount("/", FileServer::from(relative!("static"))) .launch() |