Add support for creating and reusing site.toml for init.

This commit is contained in:
Dorian 2019-08-08 17:55:36 -04:00
parent a37e33993a
commit dc3ce055d8
2 changed files with 39 additions and 2 deletions

View File

@ -98,6 +98,13 @@ dependencies = ["build-js", "prepare-plugins-packaging"]
[tasks.init-sample-site]
category = "Rookeries"
describe = "Initialize the sample site to test the static site generator."
command = "cargo"
args = ["run", "--", "init", "docs"]
# TODO: Remove this after init command works
[tasks.init-sample-site-temp]
category = "Rookeries"
describe = "Initialize the sample site to test the static site generator."
script = [
"mkdir -p docs/template",
"cp -vR template/*.html docs/template/",

View File

@ -1,5 +1,6 @@
#[macro_use]
extern crate serde_derive;
extern crate chrono;
extern crate copy_dir;
extern crate docopt;
extern crate env_logger;
@ -17,6 +18,7 @@ extern crate rookeries;
use actix_web::{App, HttpServer};
use actix_web::middleware::Logger;
use chrono::prelude::*;
use colored::Colorize;
use docopt::Docopt;
use env_logger::{Builder, Env};
@ -133,7 +135,6 @@ fn main() {
}
if args.cmd_build {
// TODO: Make more robust against errors and absences of files.
let project_directory = get_project_directory(&args);
// Check if project manifest is available.
@ -212,7 +213,7 @@ fn main() {
info!("Preparing build directory...");
let build_directory = project_directory.clone().join("build");
if build_directory.exists() && build_directory.is_dir() {
info!("{} Recreating build directory...", "".yellow());
info!("{} Recreating build directory...", "".yellow());
remove_dir_all(&build_directory).expect("Failure!");
create_dir(&build_directory).expect("Failure!");
info!("{} Created a build directory.", "".green());
@ -345,6 +346,8 @@ fn main() {
// TODO: Remove the copied over base_index.html
// Copy over plugins too!
info!("");
info!("Activate plugins...");
// TODO: Copy over only active and available markdown plugins.
let plugin_list = vec!["hello-world", "dark-mode-switch"];
let plugins_install_path = Path::new(&project_directory)
@ -385,6 +388,33 @@ fn main() {
if args.cmd_init {
info!("");
info!("Initializing a new site...");
// Create a site toml if one is missing.
let project_directory = get_project_directory(&args);
let project_manifest = project_directory.clone().join("site.toml");
match &project_manifest.exists() {
true => {
info!("{} Found existing site.toml. Skipping.", "".yellow());
},
false => {
// TODO: Support an interactive setup of the Rookeries site.
let mut site = Site::default();
site.name = "New Rookeries Site".to_string();
let site_toml_content = toml::to_string(&site).unwrap();
// TODO: Consider a more complex template for the site.
let rookeries_version = env!("CARGO_PKG_VERSION");
let generation_timestamp: DateTime<Local> = Local::now();
let generation_timestamp = generation_timestamp.format("%B %e, %Y @ %R").to_string();
let site_toml_header = format!("# Site generated by Rookeries v{} on {}", rookeries_version, generation_timestamp);
let site_toml = format!("{}\n\n{}", site_toml_header, site_toml_content);
write(&project_manifest, site_toml).expect("Failed to write site.toml");
info!("{} Created a site.toml!", "".green());
}
}
}
}