aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2023-06-22 21:37:10 +0100
committerLibravatar cel 🌸 <cel@blos.sm>2023-06-22 21:37:10 +0100
commitab529917847641190f21129804bbda1784b4f998 (patch)
treedfdd39286d330dd62339ade0499471b70187ae04 /src/main.rs
parentbc5ac494c6162743810b9aeb1cda4f22d94a486a (diff)
downloadblossom-ab529917847641190f21129804bbda1784b4f998.tar.gz
blossom-ab529917847641190f21129804bbda1784b4f998.tar.bz2
blossom-ab529917847641190f21129804bbda1784b4f998.zip
implement atom syndication
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs16
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()