Clippy run

This commit is contained in:
Vincent Prouillet 2017-03-19 19:29:43 +09:00
parent 7e496878e5
commit cd70aac065
3 changed files with 11 additions and 11 deletions

View file

@ -187,7 +187,7 @@ 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 = find_related_assets(path.parent().unwrap());
if !page.assets.is_empty() && page.file_name != "index" { if !page.assets.is_empty() && page.file_name != "index" {
bail!("Page `{}` has assets but is not named index.md", path.display()); bail!("Page `{}` has assets but is not named index.md", path.display());

View file

@ -74,7 +74,7 @@ impl Site {
let mut site = Site { let mut site = Site {
base_path: path.to_path_buf(), base_path: path.to_path_buf(),
config: get_config(&path), config: get_config(path),
pages: HashMap::new(), pages: HashMap::new(),
sections: BTreeMap::new(), sections: BTreeMap::new(),
templates: tera, templates: tera,
@ -130,7 +130,7 @@ impl Site {
grandparent_paths.entry(grand_parent).or_insert_with(|| vec![]).push(section.clone()); grandparent_paths.entry(grand_parent).or_insert_with(|| vec![]).push(section.clone());
} }
for (parent_path, section) in sections.iter_mut() { for (parent_path, section) in &mut sections {
match grandparent_paths.get(parent_path) { match grandparent_paths.get(parent_path) {
Some(paths) => section.subsections.extend(paths.clone()), Some(paths) => section.subsections.extend(paths.clone()),
None => continue, None => continue,
@ -219,7 +219,7 @@ impl Site {
// Copy the nesting of the content directory if we have sections for that page // Copy the nesting of the content directory if we have sections for that page
let mut current_path = public.to_path_buf(); let mut current_path = public.to_path_buf();
for component in page.url.split("/") { for component in page.url.split('/') {
current_path.push(component); current_path.push(component);
if !current_path.exists() { if !current_path.exists() {

View file

@ -23,34 +23,34 @@ fn test_can_parse_site() {
let posts_path = path.join("content").join("posts"); let posts_path = path.join("content").join("posts");
// Make sure we remove all the pwd + content from the sections // Make sure we remove all the pwd + content from the sections
let basic = site.pages.get(&posts_path.join("simple.md")).unwrap(); let basic = &site.pages[&posts_path.join("simple.md")];
assert_eq!(basic.components, vec!["posts".to_string()]); assert_eq!(basic.components, vec!["posts".to_string()]);
// Make sure the page with a url doesn't have any sections // Make sure the page with a url doesn't have any sections
let url_post = site.pages.get(&posts_path.join("fixed-url.md")).unwrap(); let url_post = &site.pages[&posts_path.join("fixed-url.md")];
assert!(url_post.components.is_empty()); assert!(url_post.components.is_empty());
// Make sure the article in a folder with only asset doesn't get counted as a section // Make sure the article in a folder with only asset doesn't get counted as a section
let asset_folder_post = site.pages.get(&posts_path.join("with-assets").join("index.md")).unwrap(); let asset_folder_post = &site.pages[&posts_path.join("with-assets").join("index.md")];
assert_eq!(asset_folder_post.components, vec!["posts".to_string()]); assert_eq!(asset_folder_post.components, vec!["posts".to_string()]);
// That we have the right number of sections // That we have the right number of sections
assert_eq!(site.sections.len(), 4); assert_eq!(site.sections.len(), 4);
// And that the sections are correct // And that the sections are correct
let posts_section = site.sections.get(&posts_path).unwrap(); let posts_section = &site.sections[&posts_path];
assert_eq!(posts_section.subsections.len(), 1); assert_eq!(posts_section.subsections.len(), 1);
assert_eq!(posts_section.pages.len(), 5); assert_eq!(posts_section.pages.len(), 5);
let tutorials_section = site.sections.get(&posts_path.join("tutorials")).unwrap(); let tutorials_section = &site.sections[&posts_path.join("tutorials")];
assert_eq!(tutorials_section.subsections.len(), 2); assert_eq!(tutorials_section.subsections.len(), 2);
assert_eq!(tutorials_section.pages.len(), 0); assert_eq!(tutorials_section.pages.len(), 0);
let devops_section = site.sections.get(&posts_path.join("tutorials").join("devops")).unwrap(); let devops_section = &site.sections[&posts_path.join("tutorials").join("devops")];
assert_eq!(devops_section.subsections.len(), 0); assert_eq!(devops_section.subsections.len(), 0);
assert_eq!(devops_section.pages.len(), 2); assert_eq!(devops_section.pages.len(), 2);
let prog_section = site.sections.get(&posts_path.join("tutorials").join("programming")).unwrap(); let prog_section = &site.sections[&posts_path.join("tutorials").join("programming")];
assert_eq!(prog_section.subsections.len(), 0); assert_eq!(prog_section.subsections.len(), 0);
assert_eq!(prog_section.pages.len(), 2); assert_eq!(prog_section.pages.len(), 2);
} }