From fec60900f56f0c0842c76c0894c4c3172ef1a891 Mon Sep 17 00:00:00 2001 From: Michal Vanko Date: Sun, 24 Nov 2024 14:06:14 +0100 Subject: [PATCH] add images to rss feed --- Cargo.toml | 1 + src/feed.rs | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f2259c5..8dccadb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ rayon = "1.10.0" syntect = "5.2.0" indoc = "2.0.5" askama_escape = "0.10.3" +mime_guess = "2.0.5" [build] rustflags = ["-Z", "threads=8"] diff --git a/src/feed.rs b/src/feed.rs index 5a6421f..7a573e5 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -1,7 +1,7 @@ use axum::http::{header, StatusCode}; use axum::response::IntoResponse; use chrono::Utc; -use rss::{ChannelBuilder, GuidBuilder, Item, ItemBuilder}; +use rss::{ChannelBuilder, EnclosureBuilder, GuidBuilder, Item, ItemBuilder}; use crate::blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH}; use crate::filters::{parse_markdown, truncate_md}; @@ -26,7 +26,6 @@ pub async fn render_rss_feed() -> Result { ItemBuilder::default() .title(Some(post.metadata.title)) .link(Some(format!("https://michalvanko.dev/blog/{}", post.slug))) - // TODO Description should be just a preview .description({ let truncated = truncate_md(&post.body, 2).unwrap_or("Can't parse post body".to_string()); @@ -34,6 +33,23 @@ pub async fn render_rss_feed() -> Result { .unwrap_or("Can't process truncated post body".to_string()); Some(parsed_md) }) + .content({ + let parsed_md = parse_markdown(&post.body) + .unwrap_or("Can't process full post body".to_string()); + Some(parsed_md) + }) + .enclosure({ + post.metadata.thumbnail.map(|src| { + let mime_type = mime_guess::from_path(&src) + .first() + .map(|mime| mime.to_string()) + .unwrap_or("image".to_string()); + EnclosureBuilder::default() + .url(src) + .mime_type(mime_type) + .build() + }) + }) .guid(Some( GuidBuilder::default() .value(format!("https://michalvanko.dev/blog/{}", post.slug))