From 35e848e377b5d52b764411e0cfaa902eabdc3c68 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 26 Jul 2020 22:14:19 -0400 Subject: [PATCH] also fix RSS feeds --- Cargo.lock | 95 +------------------------------------- Cargo.toml | 1 - lib/patreon/src/lib.rs | 3 -- src/app.rs | 15 ------ src/handlers/feeds.rs | 7 +-- src/post/mod.rs | 16 ------- templates/blog_atom.rs.xml | 4 +- templates/blog_rss.rs.xml | 20 ++++++++ 8 files changed, 26 insertions(+), 135 deletions(-) create mode 100644 templates/blog_rss.rs.xml diff --git a/Cargo.lock b/Cargo.lock index 9591064..d9b87ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,7 +273,7 @@ dependencies = [ "ansi_term", "atty", "bitflags", - "strsim 0.8.0", + "strsim", "textwrap", "unicode-width", "vec_map", @@ -339,66 +339,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "darling" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.9.3", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" -dependencies = [ - "darling_core", - "quote", - "syn", -] - -[[package]] -name = "derive_builder" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" -dependencies = [ - "darling", - "derive_builder_core", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "derive_builder_core" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "dhall" version = "0.5.3" @@ -871,12 +811,6 @@ dependencies = [ "tokio-tls", ] -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "idna" version = "0.2.0" @@ -1530,16 +1464,6 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -[[package]] -name = "quick-xml" -version = "0.17.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe1e430bdcf30c9fdc25053b9c459bb1a4672af4617b6c783d7d91dc17c6bbb0" -dependencies = [ - "encoding_rs", - "memchr", -] - [[package]] name = "quote" version = "1.0.7" @@ -1780,16 +1704,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" -[[package]] -name = "rss" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99979205510c60f80a119dedbabd0b8426517384edf205322f8bcd51796bcef9" -dependencies = [ - "derive_builder", - "quick-xml", -] - [[package]] name = "ructe" version = "0.11.4" @@ -2033,12 +1947,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -[[package]] -name = "strsim" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" - [[package]] name = "syn" version = "1.0.35" @@ -2620,7 +2528,6 @@ dependencies = [ "pretty_env_logger", "prometheus", "rand 0.7.3", - "rss", "ructe", "serde", "serde_dhall", diff --git a/Cargo.toml b/Cargo.toml index 867dbc4..3d8e8da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ mime = "0.3.0" pretty_env_logger = "0" prometheus = { version = "0.9", default-features = false, features = ["process"] } rand = "0" -rss = "1" serde_dhall = "0.5.3" serde = { version = "1", features = ["derive"] } serde_yaml = "0.8" diff --git a/lib/patreon/src/lib.rs b/lib/patreon/src/lib.rs index 07e6228..57e2c02 100644 --- a/lib/patreon/src/lib.rs +++ b/lib/patreon/src/lib.rs @@ -1,6 +1,3 @@ -#[macro_use] -extern crate log; - use serde::{Deserialize, Serialize}; use thiserror::Error; use chrono::prelude::*; diff --git a/src/app.rs b/src/app.rs index 4fd143d..eab1de9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -64,7 +64,6 @@ pub struct State { pub talks: Vec, pub everything: Vec, pub jf: jsonfeed::Feed, - pub rf: rss::Channel, pub sitemap: Vec, pub patrons: Option, } @@ -91,8 +90,6 @@ pub async fn init(cfg: PathBuf) -> Result { everything.sort(); everything.reverse(); - let mut ri: Vec = vec![]; - let mut jfb = jsonfeed::Feed::builder() .title("Christine Dodrill's Blog") .description("My blog posts and rants about various technology things.") @@ -111,19 +108,8 @@ pub async fn init(cfg: PathBuf) -> Result { for post in &everything { let post = post.clone(); jfb = jfb.item(post.clone().into()); - ri.push(post.clone().into()); } - let rf = { - let mut rf = rss::ChannelBuilder::default(); - rf.title("Christine Dodrill's Blog"); - rf.link("https://christine.website/blog"); - rf.generator(crate::APPLICATION_NAME.to_string()); - rf.items(ri); - - rf.build().unwrap() - }; - let mut sm: Vec = vec![]; let smw = sitemap::writer::SiteMapWriter::new(&mut sm); let mut urlwriter = smw.start_urlset()?; @@ -152,7 +138,6 @@ pub async fn init(cfg: PathBuf) -> Result { talks: talks, everything: everything, jf: jfb.build(), - rf: rf, sitemap: sm, patrons: patrons().await?, }) diff --git a/src/handlers/feeds.rs b/src/handlers/feeds.rs index bb1a819..752b08c 100644 --- a/src/handlers/feeds.rs +++ b/src/handlers/feeds.rs @@ -20,7 +20,6 @@ pub async fn jsonfeed(state: Arc) -> Result { #[derive(Debug)] pub enum RenderError { - WriteRss(rss::Error), Build(warp::http::Error), IO(io::Error), } @@ -46,10 +45,8 @@ pub async fn rss(state: Arc) -> Result { HIT_COUNTER.with_label_values(&["rss"]).inc(); let state = state.clone(); let mut buf = Vec::new(); - state - .rf - .write_to(&mut buf) - .map_err(RenderError::WriteRss) + templates::blog_rss_xml(&mut buf, state.everything.clone()) + .map_err(RenderError::IO) .map_err(warp::reject::custom)?; Response::builder() .status(200) diff --git a/src/post/mod.rs b/src/post/mod.rs index 4014cf3..3974d89 100644 --- a/src/post/mod.rs +++ b/src/post/mod.rs @@ -52,22 +52,6 @@ impl Into for Post { } } -impl Into for Post { - fn into(self) -> rss::Item { - let mut guid = rss::Guid::default(); - guid.set_value(format!("https://christine.website/{}", self.link)); - let mut result = rss::ItemBuilder::default(); - result.title(Some(self.front_matter.title)); - result.link(format!("https://christine.website/{}", self.link)); - result.guid(guid); - result.author(Some("me@christine.website (Christine Dodrill)".to_string())); - result.content(self.body_html); - result.pub_date(self.date.to_rfc2822()); - - result.build().unwrap() - } -} - impl Ord for Post { fn cmp(&self, other: &Self) -> Ordering { self.partial_cmp(&other).unwrap() diff --git a/templates/blog_atom.rs.xml b/templates/blog_atom.rs.xml index 399c9a1..c6fd32c 100644 --- a/templates/blog_atom.rs.xml +++ b/templates/blog_atom.rs.xml @@ -1,4 +1,5 @@ @use crate::post::Post; +@use chrono::Utc; @(posts: Vec) @@ -6,6 +7,7 @@ https://christine.website/blog.atom Christine Dodrill's Blog + @Utc::now().to_rfc3339() Christine Dodrill me@@christine.website @@ -17,7 +19,7 @@ https://christine.website/@post.link @post.front_matter.title - @post.front_matter.date+00:00 + @post.date.to_rfc3339() } diff --git a/templates/blog_rss.rs.xml b/templates/blog_rss.rs.xml new file mode 100644 index 0000000..02b5ce0 --- /dev/null +++ b/templates/blog_rss.rs.xml @@ -0,0 +1,20 @@ +@use crate::post::Post; + +@(posts: Vec) + + + + Christine Dodrill's Blog + https://christine.website/blog + Tech, philosophy and more + @for post in posts { + + @post.front_matter.title + https://christine.website/@post.link + + @post.date.to_rfc2822() + + + } + +