diff options
author | cel 🌸 <cel@blos.sm> | 2023-06-22 21:37:10 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-06-22 21:37:10 +0100 |
commit | ab529917847641190f21129804bbda1784b4f998 (patch) | |
tree | dfdd39286d330dd62339ade0499471b70187ae04 /src/main.rs | |
parent | bc5ac494c6162743810b9aeb1cda4f22d94a486a (diff) | |
download | blossom-ab529917847641190f21129804bbda1784b4f998.tar.gz blossom-ab529917847641190f21129804bbda1784b4f998.tar.bz2 blossom-ab529917847641190f21129804bbda1784b4f998.zip |
implement atom syndication
Diffstat (limited to '')
-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() |