diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-27 22:40:56 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-27 22:47:46 +0100 |
commit | 261a71a0a4ad42da84d310d86137aac3de9f843b (patch) | |
tree | 5d04ef8c9e13bee56f8152e62dd4f35c7ef24478 /pkgs/by-name/ba/back/src | |
parent | feat(back/src/issues/issue): implement Display for Author (diff) | |
download | nixos-server-261a71a0a4ad42da84d310d86137aac3de9f843b.zip |
feat(back): add rss feed
Co-authored-by: Silas Schöffel <sils@sils.li>
Diffstat (limited to '')
-rw-r--r-- | pkgs/by-name/ba/back/src/main.rs | 3 | ||||
-rw-r--r-- | pkgs/by-name/ba/back/src/web/mod.rs | 26 |
2 files changed, 28 insertions, 1 deletions
diff --git a/pkgs/by-name/ba/back/src/main.rs b/pkgs/by-name/ba/back/src/main.rs index b75737a..961c39b 100644 --- a/pkgs/by-name/ba/back/src/main.rs +++ b/pkgs/by-name/ba/back/src/main.rs @@ -14,6 +14,7 @@ use std::process; use clap::Parser; use config::BackConfig; use rocket::routes; +use web::feed; use crate::web::{closed, open, show_issue, styles}; @@ -39,7 +40,7 @@ async fn rocket_main() -> Result<(), error::Error> { let config = BackConfig::from_config_file(&args.config_file)?; rocket::build() - .mount("/", routes![open, closed, show_issue, styles]) + .mount("/", routes![open, closed, show_issue, styles, feed]) .manage(config) .ignite() .await 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<BackConfig>) -> error::Result<RawHtml<String>> { issue_list_boilerplate(config, Status::Closed, Status::Open) } +#[get("/issues/feed")] +pub fn feed(config: &State<BackConfig>) -> error::Result<RawHtml<String>> { + use rss::{ChannelBuilder, Item, ItemBuilder}; + + let items: Vec<Item> = 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/<prefix>")] pub fn show_issue( config: &State<BackConfig>, |