also fix RSS feeds

This commit is contained in:
Cadey Ratio 2020-07-26 22:14:19 -04:00
parent 309443d6b7
commit 35e848e377
8 changed files with 26 additions and 135 deletions

95
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -1,6 +1,3 @@
#[macro_use]
extern crate log;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use chrono::prelude::*;

View File

@ -64,7 +64,6 @@ pub struct State {
pub talks: Vec<Post>,
pub everything: Vec<Post>,
pub jf: jsonfeed::Feed,
pub rf: rss::Channel,
pub sitemap: Vec<u8>,
pub patrons: Option<patreon::Users>,
}
@ -91,8 +90,6 @@ pub async fn init(cfg: PathBuf) -> Result<State> {
everything.sort();
everything.reverse();
let mut ri: Vec<rss::Item> = 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<State> {
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<u8> = 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<State> {
talks: talks,
everything: everything,
jf: jfb.build(),
rf: rf,
sitemap: sm,
patrons: patrons().await?,
})

View File

@ -20,7 +20,6 @@ pub async fn jsonfeed(state: Arc<State>) -> Result<impl Reply, Rejection> {
#[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<State>) -> Result<impl Reply, Rejection> {
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)

View File

@ -52,22 +52,6 @@ impl Into<jsonfeed::Item> for Post {
}
}
impl Into<rss::Item> 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()

View File

@ -1,4 +1,5 @@
@use crate::post::Post;
@use chrono::Utc;
@(posts: Vec<Post>)
@ -6,6 +7,7 @@
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://christine.website/blog.atom</id>
<title>Christine Dodrill's Blog</title>
<updated>@Utc::now().to_rfc3339()</updated>
<author>
<name>Christine Dodrill</name>
<email>me@@christine.website</email>
@ -17,7 +19,7 @@
<entry>
<id>https://christine.website/@post.link</id>
<title>@post.front_matter.title</title>
<updated>@post.front_matter.date+00:00</updated>
<updated>@post.date.to_rfc3339()</updated>
<link href="https://christine.website/@post.link" rel="alternate"/>
</entry>
}

20
templates/blog_rss.rs.xml Normal file
View File

@ -0,0 +1,20 @@
@use crate::post::Post;
@(posts: Vec<Post>)
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Christine Dodrill's Blog</title>
<link>https://christine.website/blog</link>
<description>Tech, philosophy and more</description>
@for post in posts {
<item>
<title>@post.front_matter.title</title>
<link>https://christine.website/@post.link</link>
<description></description>
<pubDate>@post.date.to_rfc2822()</pubDate>
</item>
}
</channel>
</rss>