Get assets of page only if file is named index.md
This commit is contained in:
parent
53b0ec0244
commit
414457ed92
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -9,3 +9,5 @@ benches/huge-blog
|
||||||
benches/small-kb
|
benches/small-kb
|
||||||
benches/medium-kb
|
benches/medium-kb
|
||||||
benches/huge-kb
|
benches/huge-kb
|
||||||
|
current.bench
|
||||||
|
now.bench
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! Benchmarking generated sites of various sizes
|
||||||
|
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
extern crate test;
|
extern crate test;
|
||||||
extern crate gutenberg;
|
extern crate gutenberg;
|
||||||
|
@ -40,16 +42,16 @@ fn bench_loading_medium_blog(b: &mut test::Bencher) {
|
||||||
b.iter(|| site.load().unwrap());
|
b.iter(|| site.load().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
//#[bench]
|
||||||
fn bench_loading_medium_blog_with_syntax_highlighting(b: &mut test::Bencher) {
|
//fn bench_loading_medium_blog_with_syntax_highlighting(b: &mut test::Bencher) {
|
||||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
// let mut path = env::current_dir().unwrap().to_path_buf();
|
||||||
path.push("benches");
|
// path.push("benches");
|
||||||
path.push("medium-blog");
|
// path.push("medium-blog");
|
||||||
let mut site = Site::new(&path, "config.toml").unwrap();
|
// let mut site = Site::new(&path, "config.toml").unwrap();
|
||||||
site.config.highlight_code = Some(true);
|
// site.config.highlight_code = Some(true);
|
||||||
|
//
|
||||||
b.iter(|| site.load().unwrap());
|
// b.iter(|| site.load().unwrap());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_loading_big_blog(b: &mut test::Bencher) {
|
fn bench_loading_big_blog(b: &mut test::Bencher) {
|
3
benches/unit.rs
Normal file
3
benches/unit.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
//! Benchmarking individual functions of Gutenberg
|
||||||
|
|
||||||
|
|
|
@ -108,10 +108,10 @@ impl Page {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let content = read_file(path)?;
|
let content = read_file(path)?;
|
||||||
let mut page = Page::parse(path, &content, config)?;
|
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" {
|
if page.file.name == "index" {
|
||||||
bail!("Page `{}` has assets ({:?}) but is not named index.md", path.display(), page.assets);
|
page.assets = find_related_assets(path.parent().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(page)
|
Ok(page)
|
||||||
|
@ -322,16 +322,4 @@ Hello world
|
||||||
let page = res.unwrap();
|
let page = res.unwrap();
|
||||||
assert_eq!(page.file.parent, path.join("content").join("posts"));
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)> {
|
pub fn split_page_content(file_path: &Path, content: &str) -> Result<(PageFrontMatter, String)> {
|
||||||
let (front_matter, content) = split_content(file_path, content)?;
|
let (front_matter, content) = split_content(file_path, content)?;
|
||||||
let meta = PageFrontMatter::parse(&front_matter)
|
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))
|
Ok((meta, content))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue