summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-27 22:40:56 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-27 22:47:46 +0100
commit261a71a0a4ad42da84d310d86137aac3de9f843b (patch)
tree5d04ef8c9e13bee56f8152e62dd4f35c7ef24478
parentfeat(back/src/issues/issue): implement Display for Author (diff)
downloadnixos-server-261a71a0a4ad42da84d310d86137aac3de9f843b.zip
feat(back): add rss feed
Co-authored-by: Silas Schöffel <sils@sils.li>
-rw-r--r--pkgs/by-name/ba/back/Cargo.lock123
-rw-r--r--pkgs/by-name/ba/back/Cargo.toml1
-rw-r--r--pkgs/by-name/ba/back/src/main.rs3
-rw-r--r--pkgs/by-name/ba/back/src/web/mod.rs26
4 files changed, 152 insertions, 1 deletions
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
@@ -165,6 +165,19 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -194,6 +207,7 @@ dependencies = [
  "gix",
  "markdown",
  "rocket",
+ "rss",
  "serde",
  "serde_json",
  "sha2",
@@ -420,6 +434,41 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -443,6 +492,37 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -486,6 +566,15 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1859,6 +1948,12 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2139,6 +2234,12 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2314,6 +2415,16 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2507,6 +2618,18 @@ dependencies = [
 ]
 
 [[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"
 source = "registry+https://github.com/rust-lang/crates.io-index"
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<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>,