shtola

ssg in rust
git clone https://tilde.team/~marisa/repo/shtola.git
Log | Files | Refs | LICENSE

commit a1c3c453f23c020b1926924c6526182fcc4c5728
parent c7655127b2978bb82ae6c67e07709bfddd5aea49
Author: marisa <mokou@posteo.de>
Date:   Sat,  9 Nov 2019 22:42:43 +0100

Fix frontmatter condition

Diffstat:
Mshtola/src/lib.rs | 29+++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/shtola/src/lib.rs b/shtola/src/lib.rs @@ -74,7 +74,7 @@ pub struct IR { config: Config, } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] pub struct Config { ignores: Vec<PathBuf>, source: PathBuf, @@ -83,6 +83,18 @@ pub struct Config { frontmatter: bool, } +impl Default for Config { + fn default() -> Self { + Config { + ignores: Vec::new(), + source: PathBuf::from("."), + destination: PathBuf::from("./dest"), + clean: false, + frontmatter: true, + } + } +} + #[derive(Debug, Clone)] pub struct ShFile { frontmatter: Vec<Yaml>, @@ -100,7 +112,7 @@ fn read_dir(source: &PathBuf, frontmatter: bool) -> Result<HashMap<PathBuf, ShFi let file: ShFile; let mut content = String::new(); fs::File::open(path)?.read_to_string(&mut content)?; - if !frontmatter { + if frontmatter { let (matter, content) = frontmatter::lexer(&content); let yaml = frontmatter::to_yaml(&matter); file = ShFile { @@ -187,3 +199,16 @@ fn frontmatter_works() { let (_, matter_file) = r.files.iter().last().unwrap(); assert_eq!(matter_file.frontmatter[0].as_hash().unwrap().get(&Yaml::from_str("hello")).unwrap().as_str().unwrap(), "bro"); } + +#[test] +fn no_frontmatter_works() { + let mut s = Shtola::new(); + s.source("../fixtures/frontmatter"); + s.destination("../fixtures/dest_matter2"); + s.clean(true); + s.frontmatter(false); + let r = s.build().unwrap(); + let (_, matter_file) = r.files.iter().last().unwrap(); + dbg!(matter_file); + assert!(matter_file.frontmatter.is_empty()); +}