cli: Move sample data for init into single block for extraction.

This commit is contained in:
Dorian 2020-01-29 10:26:14 -05:00
parent dda7b5c6fe
commit 7debf0ce21
1 changed files with 13 additions and 11 deletions

View File

@ -15,6 +15,17 @@ use std::{collections::HashMap, fs::write};
pub fn initialize_site(project: Project) -> Result<(), RookeriesError> { pub fn initialize_site(project: Project) -> Result<(), RookeriesError> {
header_message("Initializing a new site..."); header_message("Initializing a new site...");
// TODO: Make the sample pages happen.
let mut sample_pages: HashMap<String, Value> = HashMap::new();
sample_pages.insert("index".to_string(), json!({"title": "Welcome"}));
sample_pages.insert("demo".to_string(), json!({"title": "Demo"}));
sample_pages.insert(
"license".to_string(),
json!({"title": "License (Apache v2.0)"}),
);
let sample_title = "New Rookeries Site";
let sample_plugins = vec!["hello-world", "dark-mode-switch"];
// TODO: Add support for an override flag. // TODO: Add support for an override flag.
// Build out the project directory. // Build out the project directory.
let project_directory = project.root_dir(); let project_directory = project.root_dir();
@ -28,15 +39,6 @@ pub fn initialize_site(project: Project) -> Result<(), RookeriesError> {
} }
let project_directory = build_path(&project_directory, FileType::ProjectRoot)?; let project_directory = build_path(&project_directory, FileType::ProjectRoot)?;
// TODO: Make the sample pages happen.
let mut sample_pages: HashMap<String, Value> = HashMap::new();
sample_pages.insert("index".to_string(), json!({"title": "Welcome"}));
sample_pages.insert("demo".to_string(), json!({"title": "Demo"}));
sample_pages.insert(
"license".to_string(),
json!({"title": "License (Apache v2.0)"}),
);
// Create a site toml if one is missing. // Create a site toml if one is missing.
let project_manifest = project_directory.join("site.toml"); let project_manifest = project_directory.join("site.toml");
match &project_manifest.exists() { match &project_manifest.exists() {
@ -46,7 +48,7 @@ pub fn initialize_site(project: Project) -> Result<(), RookeriesError> {
false => { false => {
// TODO: Support an interactive setup of the Rookeries site. // TODO: Support an interactive setup of the Rookeries site.
let mut site = Site::default(); let mut site = Site::default();
site.name = "New Rookeries Site".to_string(); site.name = sample_title.into();
site.pages = Some(sample_pages.clone()); site.pages = Some(sample_pages.clone());
let site_toml_content = let site_toml_content =
@ -157,7 +159,7 @@ pub fn initialize_site(project: Project) -> Result<(), RookeriesError> {
caution_message("Found existing plugins. Skipping."); caution_message("Found existing plugins. Skipping.");
} else { } else {
create_directory(&site_plugins_path, FileType::Plugin)?; create_directory(&site_plugins_path, FileType::Plugin)?;
let plugin_list = vec!["hello-world", "dark-mode-switch"]; let plugin_list = sample_plugins;
for plugin in plugin_list { for plugin in plugin_list {
let plugin_file_name = format!("{}-plugin.js", &plugin); let plugin_file_name = format!("{}-plugin.js", &plugin);
copy_file( copy_file(