Add Atom feeds for blogs and users

This commit is contained in:
Bat
2018-09-01 21:08:26 +01:00
parent 5cb994c15b
commit 97c0b533ab
8 changed files with 109 additions and 4 deletions
+18 -1
View File
@@ -1,7 +1,9 @@
use activitypub::collection::OrderedCollection;
use atom_syndication::{Entry, FeedBuilder};
use rocket::{
request::LenientForm,
response::{Redirect, Flash}
response::{Redirect, Flash, content::Content},
http::ContentType
};
use rocket_contrib::Template;
use serde_json;
@@ -129,3 +131,18 @@ fn outbox(name: String, conn: DbConn) -> ActivityStream<OrderedCollection> {
let blog = Blog::find_local(&*conn, name).unwrap();
blog.outbox(&*conn)
}
#[get("/~/<name>/atom.xml")]
fn atom_feed(name: String, conn: DbConn) -> Content<String> {
let blog = Blog::find_by_fqn(&*conn, name.clone()).expect("Unable to find blog");
let feed = FeedBuilder::default()
.title(blog.title.clone())
.id(Instance::get_local(&*conn).unwrap().compute_box("~", name, "atom.xml"))
.entries(Post::get_recents_for_blog(&*conn, &blog, 15)
.into_iter()
.map(|p| super::post_to_atom(p, &*conn))
.collect::<Vec<Entry>>())
.build()
.expect("Error building Atom feed");
Content(ContentType::new("application", "atom+xml"), feed.to_string())
}