diff --git a/.gitignore b/.gitignore index b8da44ea..8012b553 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ benches/huge-blog benches/small-kb benches/medium-kb benches/huge-kb +current.bench +now.bench diff --git a/benches/gutenberg.rs b/benches/integration.rs similarity index 90% rename from benches/gutenberg.rs rename to benches/integration.rs index 0b6b33f3..07036f25 100644 --- a/benches/gutenberg.rs +++ b/benches/integration.rs @@ -1,3 +1,5 @@ +//! Benchmarking generated sites of various sizes + #![feature(test)] extern crate test; extern crate gutenberg; @@ -40,16 +42,16 @@ fn bench_loading_medium_blog(b: &mut test::Bencher) { b.iter(|| site.load().unwrap()); } -#[bench] -fn bench_loading_medium_blog_with_syntax_highlighting(b: &mut test::Bencher) { - let mut path = env::current_dir().unwrap().to_path_buf(); - path.push("benches"); - path.push("medium-blog"); - let mut site = Site::new(&path, "config.toml").unwrap(); - site.config.highlight_code = Some(true); - - b.iter(|| site.load().unwrap()); -} +//#[bench] +//fn bench_loading_medium_blog_with_syntax_highlighting(b: &mut test::Bencher) { +// let mut path = env::current_dir().unwrap().to_path_buf(); +// path.push("benches"); +// path.push("medium-blog"); +// let mut site = Site::new(&path, "config.toml").unwrap(); +// site.config.highlight_code = Some(true); +// +// b.iter(|| site.load().unwrap()); +//} #[bench] fn bench_loading_big_blog(b: &mut test::Bencher) { diff --git a/benches/unit.rs b/benches/unit.rs new file mode 100644 index 00000000..b08b2290 --- /dev/null +++ b/benches/unit.rs @@ -0,0 +1,3 @@ +//! Benchmarking individual functions of Gutenberg + + diff --git a/src/content/page.rs b/src/content/page.rs index 390044eb..0f47ffde 100644 --- a/src/content/page.rs +++ b/src/content/page.rs @@ -108,10 +108,10 @@ impl Page { let path = path.as_ref(); let content = read_file(path)?; let mut page = Page::parse(path, &content, config)?; - page.assets = find_related_assets(path.parent().unwrap()); + page.assets = vec![]; - if !page.assets.is_empty() && page.file.name != "index" { - bail!("Page `{}` has assets ({:?}) but is not named index.md", path.display(), page.assets); + if page.file.name == "index" { + page.assets = find_related_assets(path.parent().unwrap()); } Ok(page) @@ -322,16 +322,4 @@ Hello world let page = res.unwrap(); assert_eq!(page.file.parent, path.join("content").join("posts")); } - - #[test] - fn errors_file_not_named_index_with_assets() { - let tmp_dir = TempDir::new("example").expect("create temp dir"); - File::create(tmp_dir.path().join("something.md")).unwrap(); - File::create(tmp_dir.path().join("example.js")).unwrap(); - File::create(tmp_dir.path().join("graph.jpg")).unwrap(); - File::create(tmp_dir.path().join("fail.png")).unwrap(); - - let page = Page::from_file(tmp_dir.path().join("something.md"), &Config::default()); - assert!(page.is_err()); - } } diff --git a/src/front_matter/mod.rs b/src/front_matter/mod.rs index b46fadf1..e0521418 100644 --- a/src/front_matter/mod.rs +++ b/src/front_matter/mod.rs @@ -43,7 +43,7 @@ pub fn split_section_content(file_path: &Path, content: &str) -> Result<(Section pub fn split_page_content(file_path: &Path, content: &str) -> Result<(PageFrontMatter, String)> { let (front_matter, content) = split_content(file_path, content)?; let meta = PageFrontMatter::parse(&front_matter) - .chain_err(|| format!("Error when parsing front matter of section `{}`", file_path.to_string_lossy()))?; + .chain_err(|| format!("Error when parsing front matter of page `{}`", file_path.to_string_lossy()))?; Ok((meta, content)) }