Browse Source

Get assets of page only if file is named index.md

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
414457ed92
5 changed files with 21 additions and 26 deletions
  1. +2
    -0
      .gitignore
  2. +12
    -10
      benches/integration.rs
  3. +3
    -0
      benches/unit.rs
  4. +3
    -15
      src/content/page.rs
  5. +1
    -1
      src/front_matter/mod.rs

+ 2
- 0
.gitignore View File

@@ -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

benches/gutenberg.rs → benches/integration.rs View File

@@ -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]
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] #[bench]
fn bench_loading_big_blog(b: &mut test::Bencher) { fn bench_loading_big_blog(b: &mut test::Bencher) {

+ 3
- 0
benches/unit.rs View File

@@ -0,0 +1,3 @@
//! Benchmarking individual functions of Gutenberg



+ 3
- 15
src/content/page.rs View File

@@ -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" {
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) 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());
}
} }

+ 1
- 1
src/front_matter/mod.rs View File

@@ -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…
Cancel
Save