2016-12-06 05:51:33 +00:00
|
|
|
|
2016-12-13 06:22:24 +00:00
|
|
|
use std::fs::{create_dir};
|
2016-12-06 05:51:33 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2017-03-08 00:13:50 +00:00
|
|
|
use gutenberg::errors::Result;
|
|
|
|
use gutenberg::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<P: AsRef<Path>>(name: P) -> Result<()> {
|
|
|
|
let path = name.as_ref();
|
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())?;
|
|
|
|
|
|
|
|
// 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(())
|
|
|
|
}
|