zola/src/cmd/init.rs

40 lines
819 B
Rust
Raw Normal View History

2017-07-01 07:47:41 +00:00
use std::fs::create_dir;
2016-12-06 05:51:33 +00:00
use std::path::Path;
2017-07-01 07:47:41 +00:00
use errors::Result;
use utils::fs::create_file;
2016-12-06 05:51:33 +00:00
const CONFIG: &'static str = r#"
title = "My site"
2017-02-23 08:34:57 +00:00
# replace the url below with yours
base_url = "https://example.com"
[extra]
# Put all your custom variables here
2016-12-06 05:51:33 +00:00
"#;
pub fn create_new_project(name: &str) -> Result<()> {
let path = Path::new(name);
2017-02-23 08:34:57 +00:00
2016-12-06 05:51:33 +00:00
// Better error message than the rust default
if path.exists() && path.is_dir() {
2016-12-09 11:24:05 +00:00
bail!("Folder `{}` already exists", path.to_string_lossy().to_string());
2016-12-06 05:51:33 +00:00
}
// main folder
create_dir(path)?;
create_file(&path.join("config.toml"), CONFIG.trim_left())?;
2016-12-06 05:51:33 +00:00
// content folder
create_dir(path.join("content"))?;
// layouts folder
2017-02-23 08:34:57 +00:00
create_dir(path.join("templates"))?;
2016-12-06 05:51:33 +00:00
create_dir(path.join("static"))?;
Ok(())
}