diff --git a/Cargo.toml b/Cargo.toml index 79d88a2..be96384 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,11 @@ pretty_env_logger = "0" rand = "0" ructe = "0.11" serde_dhall = "0.5.3" -serde_yaml = "0.8" serde = { version = "1", features = ["derive"] } +serde_yaml = "0.8" +thiserror = "1" tokio = { version = "0.2", features = ["macros"] } warp = "0.2" -thiserror = "1" [build-dependencies] ructe = { version = "0.11", features = ["warp02"] } diff --git a/src/app.rs b/src/app.rs index 124ae96..8d8c0c6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,4 @@ -use crate::signalboost::Person; +use crate::{post::Post, signalboost::Person}; use anyhow::Result; use comrak::{markdown_to_html, ComrakOptions}; use serde::Deserialize; @@ -33,6 +33,10 @@ pub struct State { pub cfg: Config, pub signalboost: Vec, pub resume: String, + pub blog: Vec, + pub gallery: Vec, + pub talks: Vec, + pub everything: Vec, } pub fn init(cfg: PathBuf) -> Result { @@ -40,10 +44,40 @@ pub fn init(cfg: PathBuf) -> Result { let sb = cfg.signalboost.clone(); let resume = fs::read_to_string(cfg.resume_fname.clone())?; let resume: String = markdown(&resume); + let blog = crate::post::load("blog")?; + let gallery = crate::post::load("gallery")?; + let talks = crate::post::load("talks")?; + let mut everything: Vec = vec![]; + + { + let blog = blog.clone(); + let gallery = gallery.clone(); + let talks = talks.clone(); + everything.extend(blog.iter().cloned()); + everything.extend(gallery.iter().cloned()); + everything.extend(talks.iter().cloned()); + }; + + everything.sort(); + everything.reverse(); Ok(State { cfg: cfg, signalboost: sb, resume: resume, + blog: blog, + gallery: gallery, + talks: talks, + everything: everything, }) } + +#[cfg(test)] +mod tests { + use anyhow::Result; + #[test] + fn init() -> Result<()> { + super::init("./config.dhall".into())?; + Ok(()) + } +} diff --git a/src/post/mod.rs b/src/post/mod.rs index e47eed8..1589aaa 100644 --- a/src/post/mod.rs +++ b/src/post/mod.rs @@ -5,7 +5,7 @@ use std::{cmp::Ordering, fs}; pub mod frontmatter; -#[derive(Eq, PartialEq, Debug)] +#[derive(Eq, PartialEq, Debug, Clone)] pub struct Post { pub front_matter: frontmatter::Data, pub link: String, @@ -60,7 +60,19 @@ mod tests { #[test] fn blog() -> Result<()> { - load("./blog")?; + load("blog")?; + Ok(()) + } + + #[test] + fn gallery() -> Result<()> { + load("gallery")?; + Ok(()) + } + + #[test] + fn talks() -> Result<()> { + load("talks")?; Ok(()) } } diff --git a/src/signalboost.rs b/src/signalboost.rs index 50ae49a..acd136a 100644 --- a/src/signalboost.rs +++ b/src/signalboost.rs @@ -10,3 +10,14 @@ pub struct Person { pub twitter: String, } + +#[cfg(test)] +mod tests { + use anyhow::Result; + #[test] + fn load() -> Result<()> { + let people: Vec = serde_dhall::from_file("./signalboost.dhall").parse()?; + + Ok(()) + } +}