From 261a71a0a4ad42da84d310d86137aac3de9f843b Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 27 Dec 2024 22:40:56 +0100 Subject: feat(back): add rss feed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Silas Schöffel --- pkgs/by-name/ba/back/src/web/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'pkgs/by-name/ba/back/src/web/mod.rs') diff --git a/pkgs/by-name/ba/back/src/web/mod.rs b/pkgs/by-name/ba/back/src/web/mod.rs index 35dc59f..c7ba9d9 100644 --- a/pkgs/by-name/ba/back/src/web/mod.rs +++ b/pkgs/by-name/ba/back/src/web/mod.rs @@ -106,6 +106,32 @@ pub fn closed(config: &State) -> error::Result> { issue_list_boilerplate(config, Status::Closed, Status::Open) } +#[get("/issues/feed")] +pub fn feed(config: &State) -> error::Result> { + use rss::{ChannelBuilder, Item, ItemBuilder}; + + let items: Vec = issues_from_repository(&config.repository.to_thread_local())? + .into_iter() + .map(|issue| issue.collapse()) + .map(|issue| { + ItemBuilder::default() + .title(issue.title.to_string()) + .author(issue.author.to_string()) + .description(issue.message.to_string()) + .pub_date(issue.timestamp.to_string()) + .build() + }) + .collect(); + + let channel = ChannelBuilder::default() + .title("Issues") + .link("http://example.com") + .description("An RSS feed.") + .items(items) + .build(); + Ok(RawHtml(channel.to_string())) +} + #[get("/issue/")] pub fn show_issue( config: &State, -- cgit 1.4.1