shtola

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

commit 634f4e92ecfc52ca05dda57de0e7b66cabc764ed
parent 2d6056ded52cc81e986d65cf6132b9254dd50ef8
Author: marisa <mokou@posteo.de>
Date:   Mon, 11 Nov 2019 22:49:57 +0100

Add tests for markdown

Diffstat:
Afixtures/markdown/dest/hello.html | 2++
Afixtures/markdown/hello.md | 3+++
Mshtola-markdown/src/lib.rs | 18+++++++++++++++++-
Mshtola/src/lib.rs | 6++++++
4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/fixtures/markdown/dest/hello.html b/fixtures/markdown/dest/hello.html @@ -0,0 +1,2 @@ +<h1>Hello!</h1> +<p>What's going <em>on</em>?</p> diff --git a/fixtures/markdown/hello.md b/fixtures/markdown/hello.md @@ -0,0 +1,3 @@ +# Hello! + +What's going _on_? diff --git a/shtola-markdown/src/lib.rs b/shtola-markdown/src/lib.rs @@ -9,9 +9,11 @@ pub fn plugin() -> Plugin { .iter() .filter(|(p, _)| p.extension().unwrap() == "md"); let mut update_hash: HashMap<PathBuf, ShFile> = HashMap::new(); + let mut removal_hash: HashMap<PathBuf, ShFile> = HashMap::new(); for (path, file) in markdown_files { let mut p = path.clone(); p.set_extension("html"); + removal_hash.insert(path.to_path_buf(), ShFile::empty()); update_hash.insert( p, ShFile { @@ -25,8 +27,22 @@ pub fn plugin() -> Plugin { ); } IR { - files: update_hash.union(ir.files), + files: update_hash.union(ir.files).difference(removal_hash), ..ir } }) } + +#[test] +fn it_works() { + use shtola::Shtola; + + let mut s = Shtola::new(); + s.source("../fixtures/markdown"); + s.destination("../fixtures/markdown/dest"); + s.clean(true); + s.register(plugin()); + let r = s.build().unwrap(); + let file: &ShFile = r.files.get(&PathBuf::from("hello.html")).unwrap(); + assert_eq!(std::str::from_utf8(&file.content).unwrap(), "<h1>Hello!</h1>\n<p>What's going <em>on</em>?</p>\n") +} diff --git a/shtola/src/lib.rs b/shtola/src/lib.rs @@ -121,6 +121,12 @@ pub struct ShFile { pub content: Vec<u8>, } +impl ShFile { + pub fn empty() -> ShFile { + ShFile { frontmatter: json!(null), content: Vec::new() } + } +} + fn read_dir( source: &PathBuf, frontmatter: bool,