Add pages to config.toml when they are created with new
This commit is contained in:
parent
cb09cb694b
commit
52b2bab5fd
25
config.toml
25
config.toml
@ -4,25 +4,18 @@ built_pages = ["test_page/about.toml", "test_page/other.toml"]
|
||||
use_default_css = true
|
||||
javascript = []
|
||||
css = []
|
||||
#before_navbar_url = "/navbar.html"
|
||||
#before_content_url = "/before_content.html"
|
||||
#after_content_url = "/after_content.html"
|
||||
#favicon = "favicon.png"
|
||||
#twitter_author = "@teascade"
|
||||
#google_robots = "all"
|
||||
#google_site_verification = ""
|
||||
|
||||
[navbar]
|
||||
items = ["about", "other", "google"]
|
||||
|
||||
[navbar.item.about]
|
||||
title = "About"
|
||||
link = "/"
|
||||
[navbar.item.google]
|
||||
title = "Google!"
|
||||
link = "https://google.com"
|
||||
|
||||
[navbar.item.other]
|
||||
title = "Other"
|
||||
link = "/other"
|
||||
[navbar.item.about]
|
||||
title = "About"
|
||||
link = "/"
|
||||
|
||||
[navbar.item.google]
|
||||
title = "Google!"
|
||||
link = "https://google.com"
|
||||
[navbar.item.other]
|
||||
title = "Other"
|
||||
link = "/other"
|
||||
|
@ -5,7 +5,7 @@ use options::NewOps;
|
||||
use logger::{LogLevel, Logger};
|
||||
use file_writer;
|
||||
use error::Error;
|
||||
use config_toml::{PageConfig, PageConfigToml};
|
||||
use config_toml::{GlobalConfigToml, PageConfig, PageConfigToml};
|
||||
|
||||
use toml;
|
||||
use pathdiff;
|
||||
@ -34,6 +34,14 @@ pub fn generate_new_page(ops: NewOps, logger: &Logger) -> Result<(), Error> {
|
||||
markdown_path = ensure_extension(toml_path.clone(), "md", true)?;
|
||||
}
|
||||
|
||||
logger.log(
|
||||
LogLevel::INFO,
|
||||
format!(
|
||||
"Creating page config at {:?} and markdown at {:?}",
|
||||
toml_path, markdown_path
|
||||
),
|
||||
);
|
||||
|
||||
logger.log(
|
||||
LogLevel::DETAIL,
|
||||
format!("Creating a new .toml file at {:?}", toml_path),
|
||||
@ -61,6 +69,11 @@ pub fn generate_new_page(ops: NewOps, logger: &Logger) -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
logger.log(
|
||||
LogLevel::DETAILER,
|
||||
format!("Generating page config.toml contents"),
|
||||
);
|
||||
|
||||
let page_config = PageConfigToml {
|
||||
page: PageConfig {
|
||||
html_path: html_path.to_str().unwrap().to_owned(),
|
||||
@ -96,6 +109,34 @@ pub fn generate_new_page(ops: NewOps, logger: &Logger) -> Result<(), Error> {
|
||||
|
||||
file_writer::write_file(markdown_path, PLACEHOLDER_MARKDOWN, ops.overwrite)?;
|
||||
|
||||
logger.log(
|
||||
LogLevel::INFO,
|
||||
format!("Adding page config path to config.toml"),
|
||||
);
|
||||
let mut config = GlobalConfigToml::get_config()?;
|
||||
config
|
||||
.website
|
||||
.built_pages
|
||||
.push(toml_path.to_str().unwrap().to_owned());
|
||||
|
||||
logger.log(
|
||||
LogLevel::DETAIL,
|
||||
format!("Re-serializing config and writing it"),
|
||||
);
|
||||
|
||||
match toml::ser::to_string(&config) {
|
||||
Ok(text) => file_writer::write_file(PathBuf::from("config.toml"), text, ops.overwrite)?,
|
||||
Err(err) => {
|
||||
return Err(Error::new(
|
||||
LogLevel::SEVERE,
|
||||
format!(
|
||||
"Failed to serialize config.toml: {}",
|
||||
err.description().to_owned()
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user