Add option for new page to not add the page to config.toml

This commit is contained in:
Sofia 2018-04-17 00:50:28 +03:00
parent 52b2bab5fd
commit 5f2b40ad43
3 changed files with 32 additions and 27 deletions

View File

@ -12,10 +12,10 @@ items = ["about", "other", "google"]
title = "Google!"
link = "https://google.com"
[navbar.item.about]
title = "About"
link = "/"
[navbar.item.other]
title = "Other"
link = "/other"
[navbar.item.about]
title = "About"
link = "/"

View File

@ -109,31 +109,33 @@ 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());
if !ops.no_modify_config {
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"),
);
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()
),
))
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()
),
))
}
}
}

View File

@ -50,4 +50,7 @@ pub struct NewOps {
/// Overwrites existing .toml / .md files
#[structopt(short = "o", long = "overwrite")]
pub overwrite: bool,
/// Don't modify config.toml automatically
#[structopt(short = "n", long = "no-modify-config")]
pub no_modify_config: bool,
}