You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
843B

  1. use std::fs::{create_dir};
  2. use std::path::Path;
  3. use gutenberg::errors::Result;
  4. use gutenberg::create_file;
  5. const CONFIG: &'static str = r#"
  6. title = "My site"
  7. # replace the url below with yours
  8. base_url = "https://example.com"
  9. [extra]
  10. # Put all your custom variables here
  11. "#;
  12. pub fn create_new_project<P: AsRef<Path>>(name: P) -> Result<()> {
  13. let path = name.as_ref();
  14. // Better error message than the rust default
  15. if path.exists() && path.is_dir() {
  16. bail!("Folder `{}` already exists", path.to_string_lossy().to_string());
  17. }
  18. // main folder
  19. create_dir(path)?;
  20. create_file(path.join("config.toml"), CONFIG.trim_left())?;
  21. // content folder
  22. create_dir(path.join("content"))?;
  23. // layouts folder
  24. create_dir(path.join("templates"))?;
  25. create_dir(path.join("static"))?;
  26. Ok(())
  27. }