use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError};
use lemmy_websocket::LemmyContext;
-use rss::{CategoryBuilder, ChannelBuilder, GuidBuilder, Item, ItemBuilder};
+use rss::{
+ extension::dublincore::DublinCoreExtensionBuilder,
+ ChannelBuilder,
+ GuidBuilder,
+ Item,
+ ItemBuilder,
+};
use serde::Deserialize;
-use std::str::FromStr;
+use std::{collections::HashMap, str::FromStr};
use strum::ParseError;
#[derive(Deserialize)]
.route("/feeds/all.xml", web::get().to(get_all_feed));
}
+lazy_static! {
+ static ref RSS_NAMESPACE: HashMap<String, String> = {
+ let mut h = HashMap::new();
+ h.insert(
+ "dc".to_string(),
+ rss::extension::dublincore::NAMESPACE.to_string(),
+ );
+ h
+ };
+}
+
async fn get_all_feed(
info: web::Query<Params>,
context: web::Data<LemmyContext>,
let mut channel_builder = ChannelBuilder::default();
channel_builder
+ .namespaces(RSS_NAMESPACE.to_owned())
.title(&format!("{} - All", site_view.name))
.link(Settings::get().get_protocol_and_hostname())
.items(items);
let mut channel_builder = ChannelBuilder::default();
channel_builder
+ .namespaces(RSS_NAMESPACE.to_owned())
.title(&format!("{} - {}", site_view.name, user.name))
.link(user_url)
.items(items);
let mut channel_builder = ChannelBuilder::default();
channel_builder
+ .namespaces(RSS_NAMESPACE.to_owned())
.title(&format!("{} - {}", site_view.name, community.name))
.link(community.actor_id)
.items(items);
let mut channel_builder = ChannelBuilder::default();
channel_builder
+ .namespaces(RSS_NAMESPACE.to_owned())
.title(&format!("{} - Subscribed", site_view.name))
.link(Settings::get().get_protocol_and_hostname())
.items(items);
let mut channel_builder = ChannelBuilder::default();
channel_builder
+ .namespaces(RSS_NAMESPACE.to_owned())
.title(&format!("{} - Inbox", site_view.name))
.link(format!(
"{}/inbox",
for p in posts {
let mut i = ItemBuilder::default();
+ let mut dc_extension = DublinCoreExtensionBuilder::default();
i.title(p.name);
- let author_url = format!(
- "{}/u/{}",
- Settings::get().get_protocol_and_hostname(),
- p.creator_name
- );
- i.author(format!(
- "/u/{} <a href=\"{}\">(link)</a>",
- p.creator_name, author_url
- ));
+ dc_extension.creators(vec![p.creator_actor_id.to_owned()]);
let dt = DateTime::<Utc>::from_utc(p.published, Utc);
i.pub_date(dt.to_rfc2822());
p.community_name
);
- let category = CategoryBuilder::default()
- .name(format!(
- "/c/{} <a href=\"{}\">(link)</a>",
- p.community_name, community_url
- ))
- .domain(Settings::get().hostname.to_owned())
- .build()
- .map_err(|e| anyhow!(e))?;
-
- i.categories(vec![category]);
+ // TODO: for category we should just put the name of the category, but then we would have
+ // to read each community from the db
if let Some(url) = p.url {
i.link(url);
// TODO add images
let mut description = format!("submitted by <a href=\"{}\">{}</a> to <a href=\"{}\">{}</a><br>{} points | <a href=\"{}\">{} comments</a>",
- author_url,
+ p.creator_actor_id,
p.creator_name,
community_url,
p.community_name,
i.description(description);
+ i.dublin_core_ext(dc_extension.build().map_err(|e| anyhow!(e))?);
items.push(i.build().map_err(|e| anyhow!(e))?);
}