From 7ac8d80bbbea23dc98e6cb1d3f51cd7bed578894 Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Thu, 15 Feb 2018 13:15:31 +0100 Subject: [PATCH 1/8] rough stab at adding metadata support to posts to allow overriding of the title and the date because relying on the filesystem though very elegant and simple is not always what you want --- Cargo.lock | 57 ++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 ++- src/build.rs | 17 ++++++++++----- src/main.rs | 3 +++ src/metadata.rs | 47 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 src/metadata.rs diff --git a/Cargo.lock b/Cargo.lock index 80133e7..51d07ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -201,7 +202,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "leven" -version = "0.5.0" +version = "0.6.0" dependencies = [ "badlog 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -211,6 +212,7 @@ dependencies = [ "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tenjin 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -363,6 +365,11 @@ dependencies = [ "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rand" version = "0.3.20" @@ -433,6 +440,25 @@ name = "serde" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "serde_derive" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_derive_internals" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde_json" version = "1.0.9" @@ -457,6 +483,24 @@ name = "strsim" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "syn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synom" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tenjin" version = "0.5.1" @@ -538,6 +582,11 @@ name = "unicode-width" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unidecode" version = "0.2.0" @@ -664,6 +713,7 @@ dependencies = [ "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a656fdb8b6848f896df5e478a0eb9083681663e37dcb77dd16981ff65329fe8b" +"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" "checksum rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed02d09394c94ffbdfdc755ad62a132e94c3224a8354e78a1200ced34df12edf" "checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" @@ -673,9 +723,13 @@ dependencies = [ "checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526" +"checksum serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ba7591cfe93755e89eeecdbcc668885624829b020050e6aec99c2a03bd3fd0" +"checksum serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e03f1c9530c3fb0a0a5c9b826bdd9246a5921ae995d75f512ac917fc4dd55b5" "checksum serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9db7266c7d63a4c4b7fe8719656ccdd51acf1bed6124b174f933b009fb10bcb" "checksum slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f5ff4b43cb07b86c5f9236c92714a22cdf9e5a27a7d85e398e2c9403328cb8" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" +"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" +"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tenjin 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "501499d17225b3f93b7b5d9b26443d9ddfe2a38ac2e44b0bc2d953d75577359d" "checksum termcolor 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9065bced9c3e43453aa3d56f1e98590b8455b341d2fa191a1090c0dd0b242c75" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" @@ -686,6 +740,7 @@ dependencies = [ "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" +"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unidecode 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2adb95ee07cd579ed18131f2d9e7a17c25a4b76022935c7f2460d2bfae89fd2" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" diff --git a/Cargo.toml b/Cargo.toml index 0c75414..0698140 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,13 +8,14 @@ version = "0.6.0" [dependencies] badlog = "1.0" -chrono = "0.4" +chrono = { version = "0.4", features = ["serde"] } clap = "2.26" git2 = "0.6.8" log = "0.3" pulldown-cmark = "0.1" rayon = "0.9" serde = "1.0" +serde_derive = "1.0" slug = "0.1" tenjin = "0.5" toml = "0.4" diff --git a/src/build.rs b/src/build.rs index 7dda58c..04aacd7 100644 --- a/src/build.rs +++ b/src/build.rs @@ -13,6 +13,7 @@ use std::path::Path; use std::sync::mpsc::channel; use tenjin::Tenjin; use toml; +use metadata; use util::{InjectDate, cd2root, load_config, build_tenjin, cpr}; const DEFAULT_RECENTS: usize = 5; @@ -80,16 +81,22 @@ impl Post { let mut src = String::new(); File::open(&path)?.read_to_string(&mut src)?; + let (md, src) = metadata::parse_metadata(src); + let mut content = String::new(); let parser = Parser::new_ext(&src, Options::all()); pulldown_cmark::html::push_html(&mut content, parser); - let title = path.file_stem() - .unwrap() - .to_string_lossy() - .into(); + let title = md.title.unwrap_or( + path.file_stem() + .unwrap() + .to_string_lossy() + .into() + ); - let date = path.metadata()?.modified()?.into(); + let date = md.date.unwrap_or( + path.metadata()?.modified()?.into() + ); let slug = slug::slugify(&title); Ok(Post { content, title, date, slug }) diff --git a/src/main.rs b/src/main.rs index 1958c57..9e5ed56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,12 +11,15 @@ extern crate slug; #[macro_use] extern crate tenjin; extern crate toml; +#[macro_use] +extern crate serde_derive; mod build; mod error; mod init; mod theme; mod util; +mod metadata; fn main() { diff --git a/src/metadata.rs b/src/metadata.rs new file mode 100644 index 0000000..e256682 --- /dev/null +++ b/src/metadata.rs @@ -0,0 +1,47 @@ +use chrono::{DateTime, Local}; +use toml; + +#[derive(Deserialize, Default)] +pub struct Metadata { + pub title: Option, + pub date: Option>, + // pub publish: Option, // not used yet + // pub feed: Option, // not used yet +} + +pub fn parse_metadata(src:String) -> (Metadata, String) { + let mut md_found = false; + let mut md_done = false; + let mut md = Metadata::default(); + let mut md_lines = vec![]; + let mut no_md_lines = vec![]; + for line in src.lines() { + if md_done { + no_md_lines.push(line); + continue; + } + if !md_found { + if line.starts_with("+++") { + md_found = true; + } else { + md_done = true; + } + } else { + if line.starts_with("+++") { + md_done = true; + } else { + md_lines.push(line) + } + } + } + if md_found { + let md_string = md_lines.join("\n"); + info!("md: {}", md_string); + match toml::from_str::(&md_string) { + Ok(md2) => md = md2, + Err(e) => error!("Error parsing metadata: {:?}", e), + } + } + let remainder = no_md_lines.join("\n"); + (md, remainder) +} From 68b0d938663791e2c8e6db52b92eb5aca299c647 Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Fri, 16 Feb 2018 13:41:51 +0100 Subject: [PATCH 2/8] vastly simplify and avoid copying in md parsing --- src/build.rs | 2 +- src/metadata.rs | 45 +++++++++++++-------------------------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/build.rs b/src/build.rs index 04aacd7..4600d9d 100644 --- a/src/build.rs +++ b/src/build.rs @@ -81,7 +81,7 @@ impl Post { let mut src = String::new(); File::open(&path)?.read_to_string(&mut src)?; - let (md, src) = metadata::parse_metadata(src); + let (md, src) = metadata::parse_metadata(&src); let mut content = String::new(); let parser = Parser::new_ext(&src, Options::all()); diff --git a/src/metadata.rs b/src/metadata.rs index e256682..09cebf0 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -9,39 +9,20 @@ pub struct Metadata { // pub feed: Option, // not used yet } -pub fn parse_metadata(src:String) -> (Metadata, String) { - let mut md_found = false; - let mut md_done = false; +pub fn parse_metadata(src:&str) -> (Metadata, &str) { let mut md = Metadata::default(); - let mut md_lines = vec![]; - let mut no_md_lines = vec![]; - for line in src.lines() { - if md_done { - no_md_lines.push(line); - continue; - } - if !md_found { - if line.starts_with("+++") { - md_found = true; - } else { - md_done = true; - } - } else { - if line.starts_with("+++") { - md_done = true; - } else { - md_lines.push(line) - } - } + if !src.starts_with("+++") { + return (md, src) } - if md_found { - let md_string = md_lines.join("\n"); - info!("md: {}", md_string); - match toml::from_str::(&md_string) { - Ok(md2) => md = md2, - Err(e) => error!("Error parsing metadata: {:?}", e), - } + let v:Vec<&str> = src.splitn(3, "+++").collect(); + if v.len() != 3 { + return (md, src) } - let remainder = no_md_lines.join("\n"); - (md, remainder) + let md_str = v[1]; + info!("md: {}", md_str); + match toml::from_str::(&md_str) { + Ok(md2) => md = md2, + Err(e) => error!("Error parsing metadata: {:?}", e), + } + return (md, v[2]) } From 64616b718dc14ebd1487f9385b934cdc57c348f5 Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Wed, 21 Feb 2018 09:47:01 +0100 Subject: [PATCH 3/8] implement generic metadata based on toml::value::Table --- Cargo.lock | 54 ------------------------------------------------- Cargo.toml | 1 - src/build.rs | 4 ++-- src/main.rs | 2 -- src/metadata.rs | 47 +++++++++++++++++++++++++++++++++--------- 5 files changed, 39 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51d07ad..39eee67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,7 +212,6 @@ dependencies = [ "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tenjin 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -365,11 +364,6 @@ dependencies = [ "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "quote" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "rand" version = "0.3.20" @@ -440,25 +434,6 @@ name = "serde" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "serde_derive" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive_internals" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "serde_json" version = "1.0.9" @@ -483,24 +458,6 @@ name = "strsim" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "syn" -version = "0.11.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "synom" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tenjin" version = "0.5.1" @@ -582,11 +539,6 @@ name = "unicode-width" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unicode-xid" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "unidecode" version = "0.2.0" @@ -713,7 +665,6 @@ dependencies = [ "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a656fdb8b6848f896df5e478a0eb9083681663e37dcb77dd16981ff65329fe8b" -"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" "checksum rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed02d09394c94ffbdfdc755ad62a132e94c3224a8354e78a1200ced34df12edf" "checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" @@ -723,13 +674,9 @@ dependencies = [ "checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526" -"checksum serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ba7591cfe93755e89eeecdbcc668885624829b020050e6aec99c2a03bd3fd0" -"checksum serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e03f1c9530c3fb0a0a5c9b826bdd9246a5921ae995d75f512ac917fc4dd55b5" "checksum serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9db7266c7d63a4c4b7fe8719656ccdd51acf1bed6124b174f933b009fb10bcb" "checksum slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f5ff4b43cb07b86c5f9236c92714a22cdf9e5a27a7d85e398e2c9403328cb8" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" -"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tenjin 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "501499d17225b3f93b7b5d9b26443d9ddfe2a38ac2e44b0bc2d953d75577359d" "checksum termcolor 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9065bced9c3e43453aa3d56f1e98590b8455b341d2fa191a1090c0dd0b242c75" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" @@ -740,7 +687,6 @@ dependencies = [ "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" -"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unidecode 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2adb95ee07cd579ed18131f2d9e7a17c25a4b76022935c7f2460d2bfae89fd2" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" diff --git a/Cargo.toml b/Cargo.toml index 0698140..fcd7109 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ log = "0.3" pulldown-cmark = "0.1" rayon = "0.9" serde = "1.0" -serde_derive = "1.0" slug = "0.1" tenjin = "0.5" toml = "0.4" diff --git a/src/build.rs b/src/build.rs index 4600d9d..cd39bff 100644 --- a/src/build.rs +++ b/src/build.rs @@ -87,14 +87,14 @@ impl Post { let parser = Parser::new_ext(&src, Options::all()); pulldown_cmark::html::push_html(&mut content, parser); - let title = md.title.unwrap_or( + let title = md.get_string("title").unwrap_or( path.file_stem() .unwrap() .to_string_lossy() .into() ); - let date = md.date.unwrap_or( + let date = md.get_date("date").unwrap_or( path.metadata()?.modified()?.into() ); let slug = slug::slugify(&title); diff --git a/src/main.rs b/src/main.rs index 9e5ed56..3b1255b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,8 +11,6 @@ extern crate slug; #[macro_use] extern crate tenjin; extern crate toml; -#[macro_use] -extern crate serde_derive; mod build; mod error; diff --git a/src/metadata.rs b/src/metadata.rs index 09cebf0..d3044d0 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -1,13 +1,8 @@ use chrono::{DateTime, Local}; use toml; -#[derive(Deserialize, Default)] -pub struct Metadata { - pub title: Option, - pub date: Option>, - // pub publish: Option, // not used yet - // pub feed: Option, // not used yet -} +#[derive(Default)] +pub struct Metadata(toml::value::Table); pub fn parse_metadata(src:&str) -> (Metadata, &str) { let mut md = Metadata::default(); @@ -19,10 +14,42 @@ pub fn parse_metadata(src:&str) -> (Metadata, &str) { return (md, src) } let md_str = v[1]; - info!("md: {}", md_str); - match toml::from_str::(&md_str) { - Ok(md2) => md = md2, + match md_str.parse::() { + Ok(v) => { + match v { + toml::Value::Table(t) => { + md = Metadata(t) + } + x => error!("Unexpected Toml::Value: {:?}", x), + } + } Err(e) => error!("Error parsing metadata: {:?}", e), } return (md, v[2]) } + +impl Metadata { + pub fn get_string(&self, name:&str) -> Option { + match self.0.get(name) { + None => None, + Some(v) => match *v { + toml::Value::String(ref s) => Some(s.clone()), + _ => None, + } + } + } + + pub fn get_date(&self, name:&str) -> Option> { + if let Some(s) = self.get_string(name) { + match s.parse::>() { + Ok(d) => Some(d), + Err(e) => { + error!("Error parsing date {}: {:?}", s, e); + None + } + } + } else { + None + } + } +} From 15ea43d6b85bb38f65be9a50c63885203b81b43d Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Wed, 21 Feb 2018 10:10:47 +0100 Subject: [PATCH 4/8] implement more generic metadata git for FromStr parse-ables --- src/build.rs | 2 +- src/metadata.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/build.rs b/src/build.rs index cd39bff..f233664 100644 --- a/src/build.rs +++ b/src/build.rs @@ -94,7 +94,7 @@ impl Post { .into() ); - let date = md.get_date("date").unwrap_or( + let date = md.get::>("date").unwrap_or( path.metadata()?.modified()?.into() ); let slug = slug::slugify(&title); diff --git a/src/metadata.rs b/src/metadata.rs index d3044d0..a181914 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -1,4 +1,6 @@ -use chrono::{DateTime, Local}; +use std::str::FromStr; +use std::fmt::Debug; + use toml; #[derive(Default)] @@ -39,12 +41,14 @@ impl Metadata { } } - pub fn get_date(&self, name:&str) -> Option> { + pub fn get(&self, name:&str) -> Option + where T:FromStr, ::Err: Debug + { if let Some(s) = self.get_string(name) { - match s.parse::>() { - Ok(d) => Some(d), + match s.parse::() { + Ok(t) => Some(t), Err(e) => { - error!("Error parsing date {}: {:?}", s, e); + error!("Error parsing {}: {:?}", s, e); None } } From 3514333bcda1ea99610d3d84051870960a1a00b2 Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Thu, 22 Feb 2018 12:45:14 +0100 Subject: [PATCH 5/8] add atom feed support --- Cargo.lock | 190 +++++++++++++++++------------ src/build.rs | 30 +++++ src/init/theme/templates/feed.html | 26 ++++ 3 files changed, 167 insertions(+), 79 deletions(-) create mode 100644 src/init/theme/templates/feed.html diff --git a/Cargo.lock b/Cargo.lock index 39eee67..0ff57ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,14 @@ name = "ansi_term" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "arrayvec" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.6" @@ -57,20 +65,20 @@ name = "chrono" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "clap" -version = "2.29.2" +version = "2.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -85,14 +93,36 @@ dependencies = [ ] [[package]] -name = "coco" -version = "0.1.1" +name = "crossbeam-deque" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-utils" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "curl-sys" version = "0.4.1" @@ -101,7 +131,7 @@ dependencies = [ "cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.26 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -125,8 +155,8 @@ dependencies = [ "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -157,8 +187,8 @@ dependencies = [ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "libgit2-sys 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.26 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -181,15 +211,6 @@ name = "itoa" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "lazy_static" version = "0.2.11" @@ -206,10 +227,10 @@ version = "0.6.0" dependencies = [ "badlog 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.30.0 (registry+https://github.com/rust-lang/crates.io-index)", "git2 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -233,7 +254,7 @@ dependencies = [ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "libssh2-sys 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.26 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -245,7 +266,7 @@ dependencies = [ "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.26 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -289,36 +310,54 @@ dependencies = [ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "memoffset" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "nodrop" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "num" -version = "0.1.41" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-integer" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-iter" -version = "0.1.34" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.1.42" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -336,7 +375,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl-sys" -version = "0.9.24" +version = "0.9.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -357,7 +396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pulldown-cmark" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -366,11 +405,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.3.20" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -379,19 +419,19 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -409,7 +449,7 @@ dependencies = [ [[package]] name = "regex" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -441,7 +481,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -455,7 +495,7 @@ dependencies = [ [[package]] name = "strsim" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -470,10 +510,10 @@ dependencies = [ [[package]] name = "termcolor" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wincolor 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -554,7 +594,7 @@ dependencies = [ [[package]] name = "url" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -582,11 +622,6 @@ name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "winapi" version = "0.3.4" @@ -596,11 +631,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -613,16 +643,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wincolor" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [metadata] "checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4" "checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455" +"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859" "checksum badlog 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f317e5a3a103595f4858c0ababb2cd48c8ea2ff474d5956a4c0dfc5556f11f2" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" @@ -630,9 +660,11 @@ dependencies = [ "checksum cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" -"checksum clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4151c5790817c7d21bbdc6c3530811f798172915f93258244948b93ba19604a6" +"checksum clap 2.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1c07b9257a00f3fc93b7f3c417fc15607ec7a56823bc2c37ec744e266387de5b" "checksum cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "56d741ea7a69e577f6d06b36b7dff4738f680593dc27a701ffa8506b73ce28bb" -"checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" +"checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" +"checksum crossbeam-epoch 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "59796cc6cbbdc6bb319161349db0c3250ec73ec7fcb763a51065ec4e2e158552" +"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum curl-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f46e49c7125131f5afaded06944d6888b55cbdf8eba05dae73c954019b907961" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" @@ -644,7 +676,6 @@ dependencies = [ "checksum htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e9025058dae765dee5070ec375f591e2ba14638c63feff74f13805a72e523163" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "1e5d97d6708edaa407429faa671b942dc0f2727222fb6b6539bf1db936e4b121" @@ -655,30 +686,33 @@ dependencies = [ "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" -"checksum num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4083e14b542ea3eb9b5f33ff48bd373a92d78687e74f4cc0a30caeb754f0ca" -"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba" -"checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01" -"checksum num-traits 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "9936036cc70fe4a8b2d338ab665900323290efb03983c86cbe235ae800ad8017" +"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" +"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" +"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +"checksum num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f8d26da319fb45674985c78f1d1caf99aa4941f785d384a2ae36d0740bc3e2fe" +"checksum num-iter 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "4b226df12c5a59b63569dd57fafb926d91b385dfce33d8074a412411b689d593" +"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +"checksum num-traits 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7de20f146db9d920c45ee8ed8f71681fd9ade71909b48c3acbd766aa504cf10" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -"checksum openssl-sys 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "14ba54ac7d5a4eabd1d5f2c1fdeb7e7c14debfa669d94b983d01b465e767ba9e" +"checksum openssl-sys 0.9.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5a41ce2f5f2d939c80decde8fcfcf5837c203ca6c06a553510a2fcb84fa3ef1" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" -"checksum pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a656fdb8b6848f896df5e478a0eb9083681663e37dcb77dd16981ff65329fe8b" -"checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" +"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32" +"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed02d09394c94ffbdfdc755ad62a132e94c3224a8354e78a1200ced34df12edf" -"checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53" +"checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "744554e01ccbd98fff8c457c3b092cd67af62a555a43bfe97ae8a0451f7799fa" +"checksum regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "5be5347bde0c48cfd8c3fdc0766cdfe9d8a755ef84d620d6794c778c91de8b2b" "checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526" "checksum serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9db7266c7d63a4c4b7fe8719656ccdd51acf1bed6124b174f933b009fb10bcb" "checksum slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f5ff4b43cb07b86c5f9236c92714a22cdf9e5a27a7d85e398e2c9403328cb8" -"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" +"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum tenjin 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "501499d17225b3f93b7b5d9b26443d9ddfe2a38ac2e44b0bc2d953d75577359d" -"checksum termcolor 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9065bced9c3e43453aa3d56f1e98590b8455b341d2fa191a1090c0dd0b242c75" +"checksum termcolor 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "56c456352e44f9f91f774ddeeed27c1ec60a2455ed66d692059acfb1d731bda1" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" @@ -689,14 +723,12 @@ dependencies = [ "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unidecode 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2adb95ee07cd579ed18131f2d9e7a17c25a4b76022935c7f2460d2bfae89fd2" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" +"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum wincolor 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a39ee4464208f6430992ff20154216ab2357772ac871d994c51628d60e58b8b0" +"checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767" diff --git a/src/build.rs b/src/build.rs index f233664..c8e432c 100644 --- a/src/build.rs +++ b/src/build.rs @@ -203,6 +203,12 @@ fn build() -> Result<()> { error!("Failed to build `archive.html`: {}.", e); } + // Build `feed.xml`. + + if let Err(e) = build_atom_feed(&config, date_format, &tenjin, &posts) { + error!("Failed to build `feed.xml`: {}.", e); + } + // Build posts. if let Err(e) = build_posts(&config, date_format, &tenjin, &posts) { @@ -286,6 +292,30 @@ fn build_archive( Ok(()) } +fn build_atom_feed( + config: &toml::Value, + date_format: &str, + tenjin: &Tenjin, + posts: &[Post] +) -> Result<()> { + let ctx = ListContext { + config, + date_format, + posts, + }; + + let template = match tenjin.get("feed") { + Some(template) => template, + None => return Err(Error::TemplateNotFound("feed".into())), + }; + + let mut file = File::create("out/feed.xml")?; + + tenjin.render(template, &ctx, &mut file)?; + + Ok(()) +} + fn build_index( config: &toml::Value, date_format: &str, diff --git a/src/init/theme/templates/feed.html b/src/init/theme/templates/feed.html new file mode 100644 index 0000000..a5b97a6 --- /dev/null +++ b/src/init/theme/templates/feed.html @@ -0,0 +1,26 @@ + + + { config.name } + urn:uuid:{ config.uuid } + { config.date } + + + { for post in posts } + + { post.title } + { config.base_url }{ post.slug }.html + { if post.updated_date } + { post.updated_date } + { end } + + { config.author } + { config.email } + { config.home_url } + + { post.date } + + { post.content } + + + { end } + From 17d68074d3ddbfb40af1d36bf302617153b7bc8c Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Thu, 22 Feb 2018 13:56:04 +0100 Subject: [PATCH 6/8] fix date formatting for atom --- src/build.rs | 18 ++++++++++++++---- src/init/theme/templates/feed.html | 2 -- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/build.rs b/src/build.rs index c8e432c..74c50ae 100644 --- a/src/build.rs +++ b/src/build.rs @@ -23,6 +23,7 @@ struct Post { content: Html, title: String, date: DateTime, + updated_date: DateTime, slug: String, } @@ -55,6 +56,10 @@ context! { date: self.post.date, format: self.date_format, }, + updated_date => InjectDate { + date: self.post.updated_date, + format: self.date_format, + }, slug => self.post.slug.as_str(), } @@ -94,12 +99,16 @@ impl Post { .into() ); + let updated_date = md.get::>("updated_date").unwrap_or( + path.metadata()?.modified()?.into() + ); + let date = md.get::>("date").unwrap_or( path.metadata()?.modified()?.into() ); let slug = slug::slugify(&title); - Ok(Post { content, title, date, slug }) + Ok(Post { content, title, date, updated_date, slug }) } fn wrap<'a>(&'a self, date_format: &'a str) -> PostWrap<'a> { @@ -205,7 +214,7 @@ fn build() -> Result<()> { // Build `feed.xml`. - if let Err(e) = build_atom_feed(&config, date_format, &tenjin, &posts) { + if let Err(e) = build_atom_feed(&config, &tenjin, &posts) { error!("Failed to build `feed.xml`: {}.", e); } @@ -294,13 +303,14 @@ fn build_archive( fn build_atom_feed( config: &toml::Value, - date_format: &str, tenjin: &Tenjin, posts: &[Post] ) -> Result<()> { + + // date_format needs to be rfc3339 for atom let ctx = ListContext { config, - date_format, + date_format:"%FT%T%:z", posts, }; diff --git a/src/init/theme/templates/feed.html b/src/init/theme/templates/feed.html index a5b97a6..d3820a8 100644 --- a/src/init/theme/templates/feed.html +++ b/src/init/theme/templates/feed.html @@ -9,9 +9,7 @@ { post.title } { config.base_url }{ post.slug }.html - { if post.updated_date } { post.updated_date } - { end } { config.author } { config.email } From a632459b700019cde264068be18589a159702f3d Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Tue, 27 Feb 2018 12:17:24 +0100 Subject: [PATCH 7/8] encapsulate post xhtml content in xhtml ns div --- src/init/theme/templates/feed.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/init/theme/templates/feed.html b/src/init/theme/templates/feed.html index d3820a8..243847f 100644 --- a/src/init/theme/templates/feed.html +++ b/src/init/theme/templates/feed.html @@ -9,7 +9,9 @@ { post.title } { config.base_url }{ post.slug }.html + { if post.updated_date } { post.updated_date } + { end } { config.author } { config.email } @@ -17,7 +19,9 @@ { post.date } - { post.content } +
+ { post.content } +
{ end } From df1f28b768661c5fa53b3fc229c0285643550e19 Mon Sep 17 00:00:00 2001 From: Joost Yervante Damad Date: Tue, 27 Feb 2018 12:57:43 +0100 Subject: [PATCH 8/8] set current time in date config entry when it is not specified in the file --- src/util.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/util.rs b/src/util.rs index 74ae061..c731115 100644 --- a/src/util.rs +++ b/src/util.rs @@ -72,8 +72,18 @@ impl<'a, W: Write> Context for InjectDate<'a> { pub fn load_config() -> Result { let mut config = String::new(); File::open("Leven.toml")? - .read_to_string(&mut config)?; - Ok(toml::Value::from_str(&config)?) + .read_to_string(&mut config)?; + let mut config = toml::Value::from_str(&config)?; + if let Some(table) = config.as_table_mut() { + match table.get("date") { + None => { + let s = Local::now().to_rfc3339(); + table.insert("date".into(), toml::Value::String(s)); + }, + _ => (), + } + } + Ok(config) } pub fn build_tenjin() -> Result {