From 8942c1542862d9482996fe95ca38807ae5f0611e Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 13 Aug 2019 20:01:17 +0200 Subject: [PATCH] Add to changelog + rustfmt --- CHANGELOG.md | 1 + components/library/src/content/section.rs | 8 +++-- src/cmd/init.rs | 42 ++++++++++++++++------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e7a0d..f227adf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Print some counts when running `zola check` - Re-render all pages/sections when `anchor-link.html` is changed - Taxonomies can now have the same name in multiple languages +- `zola init` can now be create sites inside the current directory ## 0.8.0 (2019-06-22) diff --git a/components/library/src/content/section.rs b/components/library/src/content/section.rs index bbcedfa..21b700a 100644 --- a/components/library/src/content/section.rs +++ b/components/library/src/content/section.rs @@ -395,8 +395,12 @@ Bonjour le monde"# +++ Bonjour le monde"# .to_string(); - let res = - Section::parse(Path::new("content/subcontent/_index.fr.md"), &content, &config, &PathBuf::new()); + let res = Section::parse( + Path::new("content/subcontent/_index.fr.md"), + &content, + &config, + &PathBuf::new(), + ); assert!(res.is_ok()); let section = res.unwrap(); assert_eq!(section.lang, "fr".to_string()); diff --git a/src/cmd/init.rs b/src/cmd/init.rs index a243c1a..f032491 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -31,19 +31,29 @@ pub fn is_directory_quasi_empty(path: &Path) -> Result { if path.is_dir() { let mut entries = match path.read_dir() { Ok(entries) => entries, - Err(e) => { bail!("Could not read `{}` because of error: {}", path.to_string_lossy().to_string(), e); } + Err(e) => { + bail!( + "Could not read `{}` because of error: {}", + path.to_string_lossy().to_string(), + e + ); + } }; // If any entry raises an error or isn't hidden (i.e. starts with `.`), we raise an error if entries.any(|x| match x { - Ok(file) => !file.file_name().to_str().expect("Could not convert filename to &str").starts_with("."), - Err(_) => true + Ok(file) => !file + .file_name() + .to_str() + .expect("Could not convert filename to &str") + .starts_with('.'), + Err(_) => true, }) { - return Ok(false) + return Ok(false); } - return Ok(true) - } else { - return Ok(false) + return Ok(true); } + + Ok(false) } pub fn create_new_project(name: &str) -> Result<()> { @@ -54,7 +64,10 @@ pub fn create_new_project(name: &str) -> Result<()> { if name == "." { bail!("The current directory is not an empty folder (hidden files are ignored)."); } else { - bail!("`{}` is not an empty folder (hidden files are ignored).", path.to_string_lossy().to_string()) + bail!( + "`{}` is not an empty folder (hidden files are ignored).", + path.to_string_lossy().to_string() + ) } } } else { @@ -96,9 +109,9 @@ pub fn create_new_project(name: &str) -> Result<()> { #[cfg(test)] mod tests { - use std::env::temp_dir; - use std::fs::{create_dir,remove_dir,remove_dir_all}; use super::*; + use std::env::temp_dir; + use std::fs::{create_dir, remove_dir, remove_dir_all}; #[test] fn init_empty_directory() { @@ -108,7 +121,8 @@ mod tests { remove_dir_all(&dir).expect("Could not free test directory"); } create_dir(&dir).expect("Could not create test directory"); - let allowed = is_directory_quasi_empty(&dir).expect("An error happened reading the directory's contents"); + let allowed = is_directory_quasi_empty(&dir) + .expect("An error happened reading the directory's contents"); remove_dir(&dir).unwrap(); assert_eq!(true, allowed); } @@ -124,7 +138,8 @@ mod tests { let mut content = dir.clone(); content.push("content"); create_dir(&content).unwrap(); - let allowed = is_directory_quasi_empty(&dir).expect("An error happened reading the directory's contents"); + let allowed = is_directory_quasi_empty(&dir) + .expect("An error happened reading the directory's contents"); remove_dir(&content).unwrap(); remove_dir(&dir).unwrap(); assert_eq!(false, allowed); @@ -141,7 +156,8 @@ mod tests { let mut git = dir.clone(); git.push(".git"); create_dir(&git).unwrap(); - let allowed = is_directory_quasi_empty(&dir).expect("An error happened reading the directory's contents"); + let allowed = is_directory_quasi_empty(&dir) + .expect("An error happened reading the directory's contents"); remove_dir(&git).unwrap(); remove_dir(&dir).unwrap(); assert_eq!(true, allowed);