aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-01-31 21:23:51 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2024-01-31 21:23:51 +0000
commit1b7418483e1e0692e5e015e5eef89687a107a402 (patch)
treeb55d09a95fdda7288c0767ad8fbd3c97d20c01c7 /src
parent2426cd0f7a3aa7a181d4e9ba3447dd4471350af0 (diff)
downloadblossom-1b7418483e1e0692e5e015e5eef89687a107a402.tar.gz
blossom-1b7418483e1e0692e5e015e5eef89687a107a402.tar.bz2
blossom-1b7418483e1e0692e5e015e5eef89687a107a402.zip
add poems to main atom feed
Diffstat (limited to 'src')
-rw-r--r--src/atom.rs32
-rw-r--r--src/main.rs14
2 files changed, 31 insertions, 15 deletions
diff --git a/src/atom.rs b/src/atom.rs
index bda4c51..6e2cd1a 100644
--- a/src/atom.rs
+++ b/src/atom.rs
@@ -17,7 +17,7 @@ pub struct Context {
pub lang: String,
}
-pub async fn atom<P: Post + Clone>(ctx: Context, entries: Vec<P>) -> Feed {
+pub async fn atom<P: AsRef<dyn Post + Send + Sync>>(ctx: Context, entries: Vec<P>) -> Feed {
let mut authors = Vec::new();
let me = Person {
name: "cel".to_owned(),
@@ -65,17 +65,16 @@ pub async fn atom<P: Post + Clone>(ctx: Context, entries: Vec<P>) -> Feed {
},
id: ctx.page_url,
updated: entries
- .clone()
- .into_iter()
+ .iter()
.fold(DateTime::<Utc>::MIN_UTC, |acc, entry| {
- if let Some(updated_at) = entry.updated_at() {
+ if let Some(updated_at) = entry.as_ref().updated_at() {
if *updated_at > acc {
*updated_at
} else {
acc
}
} else {
- let published_at = entry.published_at();
+ let published_at = entry.as_ref().published_at();
if *published_at > acc {
*published_at
} else {
@@ -104,6 +103,7 @@ pub async fn atom<P: Post + Clone>(ctx: Context, entries: Vec<P>) -> Feed {
for entry in entries {
// TODO: localisation: url from lang + filtering entries translated or not
let categories = entry
+ .as_ref()
.tags()
.into_iter()
.map(|category| Category {
@@ -112,21 +112,25 @@ pub async fn atom<P: Post + Clone>(ctx: Context, entries: Vec<P>) -> Feed {
label: Some(category.to_string()),
})
.collect();
- let published = Some(entry.published_at().to_owned().into());
- let title = if let Some(title) = entry.subject() {
+ let published = Some(entry.as_ref().published_at().to_owned().into());
+ let title = if let Some(title) = entry.as_ref().subject() {
title.to_owned()
} else {
- entry.content()[..30].to_owned() + "..."
+ entry.as_ref().content()[..30].to_owned() + "..."
};
let entry = AtomEntry {
title: Text {
value: title,
base: None,
- lang: Some(entry.lang().to_owned()),
+ lang: Some(entry.as_ref().lang().to_owned()),
r#type: TextType::Text,
},
- id: entry.link(),
- updated: (*entry.updated_at().unwrap_or_else(|| entry.published_at())).into(),
+ id: entry.as_ref().link(),
+ updated: (*entry
+ .as_ref()
+ .updated_at()
+ .unwrap_or_else(|| entry.as_ref().published_at()))
+ .into(),
authors: authors.clone(),
categories,
contributors: authors.clone(),
@@ -137,9 +141,9 @@ pub async fn atom<P: Post + Clone>(ctx: Context, entries: Vec<P>) -> Feed {
summary: None,
content: Some(AtomContent {
base: None,
- lang: Some(entry.lang().to_owned()),
- value: Some(entry.content().to_owned()),
- src: Some(entry.link()),
+ lang: Some(entry.as_ref().lang().to_owned()),
+ value: Some(entry.as_ref().content().to_owned()),
+ src: Some(entry.as_ref().link()),
content_type: Some("html".to_string()),
}),
..Default::default()
diff --git a/src/main.rs b/src/main.rs
index 5ee3b2a..1c5126a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -98,7 +98,19 @@ async fn get_blog(filter_tags: Option<Query<FilterTags>>) -> Result<templates::B
#[handler]
async fn feed() -> Result<Response> {
- let posts = Blogpost::get_articles().await?;
+ let blogposts: Vec<Box<dyn Post + Send + Sync>> = Blogpost::get_articles()
+ .await?
+ .into_iter()
+ .map(|bp| Box::new(bp) as Box<dyn Post + Send + Sync>)
+ .collect();
+ let poems: Vec<Box<dyn Post + Send + Sync>> = Poem::get_articles()
+ .await?
+ .into_iter()
+ .map(|poem| Box::new(poem) as Box<dyn Post + Send + Sync>)
+ .collect();
+ let mut posts = Vec::new();
+ posts.extend(blogposts);
+ posts.extend(poems);
// TODO: i18n
let context = atom::Context {
page_title: "celeste's hard drive".to_owned(),