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/Cargo.lock | 123 ++++++++++++++++++++++++++++++++++++ pkgs/by-name/ba/back/Cargo.toml | 1 + pkgs/by-name/ba/back/src/main.rs | 3 +- pkgs/by-name/ba/back/src/web/mod.rs | 26 ++++++++ 4 files changed, 152 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/ba/back/Cargo.lock b/pkgs/by-name/ba/back/Cargo.lock index 3965cfc..a200c3c 100644 --- a/pkgs/by-name/ba/back/Cargo.lock +++ b/pkgs/by-name/ba/back/Cargo.lock @@ -164,6 +164,19 @@ dependencies = [ "syn", ] +[[package]] +name = "atom_syndication" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec03a6e158ee0f38bfba811976ae909bc2505a4a2f4049c7e8df47df3497b119" +dependencies = [ + "chrono", + "derive_builder", + "diligent-date-parser", + "never", + "quick-xml", +] + [[package]] name = "atomic" version = "0.5.3" @@ -194,6 +207,7 @@ dependencies = [ "gix", "markdown", "rocket", + "rss", "serde", "serde_json", "sha2", @@ -419,6 +433,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "dashmap" version = "6.1.0" @@ -442,6 +491,37 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_builder" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" +dependencies = [ + "derive_builder_core", + "syn", +] + [[package]] name = "devise" version = "0.4.2" @@ -485,6 +565,15 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "diligent-date-parser" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ede7d79366f419921e2e2f67889c12125726692a313bffb474bd5f37a581e9" +dependencies = [ + "chrono", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -1858,6 +1947,12 @@ dependencies = [ "syn", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.0.3" @@ -2138,6 +2233,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "never" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2313,6 +2414,16 @@ dependencies = [ "parking_lot", ] +[[package]] +name = "quick-xml" +version = "0.37.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f22f29bdff3987b4d8632ef95fd6424ec7e4e0a57e2f4fc63e489e75357f6a03" +dependencies = [ + "encoding_rs", + "memchr", +] + [[package]] name = "quote" version = "1.0.37" @@ -2506,6 +2617,18 @@ dependencies = [ "uncased", ] +[[package]] +name = "rss" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531af70fce504d369cf42ac0a9645f5a62a8ea9265de71cfa25087e9f6080c7c" +dependencies = [ + "atom_syndication", + "derive_builder", + "never", + "quick-xml", +] + [[package]] name = "rustc-demangle" version = "0.1.24" diff --git a/pkgs/by-name/ba/back/Cargo.toml b/pkgs/by-name/ba/back/Cargo.toml index 8a472e6..f1abe32 100644 --- a/pkgs/by-name/ba/back/Cargo.toml +++ b/pkgs/by-name/ba/back/Cargo.toml @@ -27,6 +27,7 @@ clap = { version = "4.5.23", features = ["derive"] } gix = "0.69.1" markdown = "1.0.0-alpha.21" rocket = "0.5.1" +rss = "2.0.11" serde = "1.0.216" serde_json = "1.0.134" sha2 = "0.10.8" 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) -> 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