aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2020-07-26 23:12:01 -0400
committerGitHub <noreply@github.com>2020-07-26 23:12:01 -0400
commit6438d334cb195af23967f28f55e7bd207e1938db (patch)
treed293518b394aabcdc071fb83aeab81d31c642cef /src
parentf9e20750dc743dfb79268fc5e7c6baa1c774030a (diff)
downloadxesite-6438d334cb195af23967f28f55e7bd207e1938db.tar.xz
xesite-6438d334cb195af23967f28f55e7bd207e1938db.zip
fix atom/RSS feeds (#186)
* fix atom feeds * also fix RSS feeds * add feeds fixed/flight journal post * fix tests
Diffstat (limited to 'src')
-rw-r--r--src/app.rs38
-rw-r--r--src/handlers/feeds.rs19
-rw-r--r--src/post/mod.rs52
3 files changed, 11 insertions, 98 deletions
diff --git a/src/app.rs b/src/app.rs
index 7b5b377..5ffca7c 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,6 +1,5 @@
use crate::{post::Post, signalboost::Person};
use anyhow::Result;
-use atom_syndication as atom;
use comrak::{markdown_to_html, ComrakOptions};
use serde::Deserialize;
use std::{fs, path::PathBuf};
@@ -65,8 +64,6 @@ pub struct State {
pub talks: Vec<Post>,
pub everything: Vec<Post>,
pub jf: jsonfeed::Feed,
- pub rf: rss::Channel,
- pub af: atom::Feed,
pub sitemap: Vec<u8>,
pub patrons: Option<patreon::Users>,
}
@@ -93,9 +90,6 @@ pub async fn init(cfg: PathBuf) -> Result<State> {
everything.sort();
everything.reverse();
- let mut ri: Vec<rss::Item> = vec![];
- let mut ai: Vec<atom::Entry> = vec![];
-
let mut jfb = jsonfeed::Feed::builder()
.title("Christine Dodrill's Blog")
.description("My blog posts and rants about various technology things.")
@@ -114,37 +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());
- ai.push(post.clone().into());
}
- let af = {
- let mut af = atom::FeedBuilder::default();
- af.title("Christine Dodrill's Blog");
- af.id("https://christine.website/blog");
- af.generator({
- let mut generator = atom::Generator::default();
- generator.set_value(env!("CARGO_PKG_NAME"));
- generator.set_version(env!("CARGO_PKG_VERSION").to_string());
- generator.set_uri("https://github.com/Xe/site".to_string());
-
- generator
- });
- af.entries(ai);
-
- af.build().unwrap()
- };
-
- 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()?;
@@ -173,8 +138,6 @@ pub async fn init(cfg: PathBuf) -> Result<State> {
talks: talks,
everything: everything,
jf: jfb.build(),
- af: af,
- rf: rf,
sitemap: sm,
patrons: patrons().await?,
})
@@ -185,6 +148,7 @@ mod tests {
use anyhow::Result;
#[tokio::test]
async fn init() -> Result<()> {
+ let _ = pretty_env_logger::try_init();
super::init("./config.dhall".into()).await?;
Ok(())
}
diff --git a/src/handlers/feeds.rs b/src/handlers/feeds.rs
index 7d7db32..752b08c 100644
--- a/src/handlers/feeds.rs
+++ b/src/handlers/feeds.rs
@@ -1,7 +1,7 @@
-use crate::app::State;
+use crate::{app::State, templates};
use lazy_static::lazy_static;
use prometheus::{opts, register_int_counter_vec, IntCounterVec};
-use std::sync::Arc;
+use std::{sync::Arc, io};
use warp::{http::Response, Rejection, Reply};
lazy_static! {
@@ -20,9 +20,8 @@ pub async fn jsonfeed(state: Arc<State>) -> Result<impl Reply, Rejection> {
#[derive(Debug)]
pub enum RenderError {
- WriteAtom(atom_syndication::Error),
- WriteRss(rss::Error),
Build(warp::http::Error),
+ IO(io::Error),
}
impl warp::reject::Reject for RenderError {}
@@ -31,10 +30,8 @@ pub async fn atom(state: Arc<State>) -> Result<impl Reply, Rejection> {
HIT_COUNTER.with_label_values(&["atom"]).inc();
let state = state.clone();
let mut buf = Vec::new();
- state
- .af
- .write_to(&mut buf)
- .map_err(RenderError::WriteAtom)
+ templates::blog_atom_xml(&mut buf, state.everything.clone())
+ .map_err(RenderError::IO)
.map_err(warp::reject::custom)?;
Response::builder()
.status(200)
@@ -48,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)
diff --git a/src/post/mod.rs b/src/post/mod.rs
index ca1f3b6..20f18e4 100644
--- a/src/post/mod.rs
+++ b/src/post/mod.rs
@@ -1,5 +1,4 @@
use anyhow::{anyhow, Result};
-use atom_syndication as atom;
use chrono::prelude::*;
use glob::glob;
use std::{cmp::Ordering, fs};
@@ -53,54 +52,6 @@ impl Into<jsonfeed::Item> for Post {
}
}
-impl Into<atom::Entry> for Post {
- fn into(self) -> atom::Entry {
- let mut content = atom::ContentBuilder::default();
-
- content.src(format!("https://christine.website/{}", self.link));
- content.content_type(Some("text/html;charset=utf-8".into()));
- content.value(Some(xml::escape::escape_str_pcdata(&self.body_html).into()));
-
- let content = content.build().unwrap();
-
- let mut result = atom::EntryBuilder::default();
- result.id(format!("https://christine.website/{}", self.link));
- result.contributors({
- let mut me = atom::Person::default();
-
- me.set_name("Christine Dodrill");
- me.set_email("me@christine.website".to_string());
- me.set_uri("https://christine.website".to_string());
-
- vec![me]
- });
- result.title(self.front_matter.title);
- let mut link = atom::Link::default();
- link.href = format!("https://christine.website/{}", self.link);
- result.links(vec![link]);
- result.content(content);
- result.published(self.date);
-
- result.build().unwrap()
- }
-}
-
-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()
@@ -160,18 +111,21 @@ mod tests {
#[test]
fn blog() -> Result<()> {
+ let _ = pretty_env_logger::try_init();
load("blog")?;
Ok(())
}
#[test]
fn gallery() -> Result<()> {
+ let _ = pretty_env_logger::try_init();
load("gallery")?;
Ok(())
}
#[test]
fn talks() -> Result<()> {
+ let _ = pretty_env_logger::try_init();
load("talks")?;
Ok(())
}