Add Atom feeds for blogs and users
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#![plugin(rocket_codegen)]
|
||||
|
||||
extern crate activitypub;
|
||||
extern crate atom_syndication;
|
||||
extern crate colored;
|
||||
extern crate diesel;
|
||||
extern crate dotenv;
|
||||
@@ -45,6 +46,7 @@ fn main() {
|
||||
routes::blogs::new,
|
||||
routes::blogs::new_auth,
|
||||
routes::blogs::create,
|
||||
routes::blogs::atom_feed,
|
||||
|
||||
routes::comments::create,
|
||||
|
||||
@@ -98,6 +100,7 @@ fn main() {
|
||||
routes::user::ap_followers,
|
||||
routes::user::new,
|
||||
routes::user::create,
|
||||
routes::user::atom_feed,
|
||||
|
||||
routes::well_known::host_meta,
|
||||
routes::well_known::nodeinfo,
|
||||
|
||||
+18
-1
@@ -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())
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use atom_syndication::{ContentBuilder, Entry, EntryBuilder, LinkBuilder, Person, PersonBuilder};
|
||||
use diesel::PgConnection;
|
||||
use rocket::{
|
||||
http::uri::{FromUriParam, UriDisplay},
|
||||
response::NamedFile
|
||||
@@ -7,6 +9,8 @@ use std::{
|
||||
path::{Path, PathBuf}
|
||||
};
|
||||
|
||||
use plume_models::posts::Post;
|
||||
|
||||
macro_rules! may_fail {
|
||||
($account:expr, $expr:expr, $template:expr, $msg:expr, | $res:ident | $block:block) => {
|
||||
{
|
||||
@@ -75,6 +79,25 @@ impl Page {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn post_to_atom(post: Post, conn: &PgConnection) -> Entry {
|
||||
EntryBuilder::default()
|
||||
.title(post.title.clone())
|
||||
.content(ContentBuilder::default()
|
||||
.value(format!("<![CDATA[{}]]>", *post.content.get()))
|
||||
.src(post.ap_url.clone())
|
||||
.content_type("html".to_string())
|
||||
.build().expect("Atom feed: content error"))
|
||||
.authors(post.get_authors(&*conn)
|
||||
.into_iter()
|
||||
.map(|a| PersonBuilder::default()
|
||||
.name(a.display_name)
|
||||
.uri(a.ap_url)
|
||||
.build().expect("Atom feed: author error"))
|
||||
.collect::<Vec<Person>>())
|
||||
.links(vec![LinkBuilder::default().href(post.ap_url).build().expect("Atom feed: link error")])
|
||||
.build().expect("Atom feed: entry error")
|
||||
}
|
||||
|
||||
pub mod blogs;
|
||||
pub mod comments;
|
||||
pub mod errors;
|
||||
|
||||
+18
-1
@@ -3,10 +3,12 @@ use activitypub::{
|
||||
collection::OrderedCollection,
|
||||
object::Article
|
||||
};
|
||||
use atom_syndication::{Entry, FeedBuilder};
|
||||
use rocket::{
|
||||
State,
|
||||
request::LenientForm,
|
||||
response::{Redirect, Flash}
|
||||
response::{Redirect, Flash, Content},
|
||||
http::ContentType
|
||||
};
|
||||
use rocket_contrib::Template;
|
||||
use serde_json;
|
||||
@@ -276,3 +278,18 @@ fn ap_followers(name: String, conn: DbConn, _ap: ApRequest) -> ActivityStream<Or
|
||||
coll.collection_props.set_items_link_vec(followers).expect("Follower collection: items error");
|
||||
ActivityStream::new(coll)
|
||||
}
|
||||
|
||||
#[get("/@/<name>/atom.xml")]
|
||||
fn atom_feed(name: String, conn: DbConn) -> Content<String> {
|
||||
let author = User::find_by_fqn(&*conn, name.clone()).expect("Unable to find author");
|
||||
let feed = FeedBuilder::default()
|
||||
.title(author.display_name.clone())
|
||||
.id(Instance::get_local(&*conn).unwrap().compute_box("~", name, "atom.xml"))
|
||||
.entries(Post::get_recents_for_author(&*conn, &author, 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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user