Add output folder path

This commit is contained in:
Sofia 2018-04-19 01:42:12 +03:00
parent b8a4e97ae2
commit c3da02b2a1
4 changed files with 35 additions and 6 deletions

View File

@ -33,7 +33,15 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
let config = fetch_config()?;
if config.global_config.website.use_default_css {
let css_path = file_writer::add_to_beginning(PathBuf::from("css/default.css"), "public")?;
let css_path = file_writer::add_to_beginning(
PathBuf::from("css/default.css"),
config
.clone()
.global_config
.website
.output
.unwrap_or("public".to_owned()),
)?;
logger.log(LogLevel::DETAIL, format!("Adding {:?}", css_path));
file_writer::write_file(&css_path, DEFAULT_CSS, opt.overwrite)?;
}
@ -112,7 +120,15 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
logger.log(LogLevel::INFO, "Writing");
for (idx, config) in configs.clone().iter().enumerate() {
let html_path = config.clone().page_config.page.html_path;
let html_path = file_writer::add_to_beginning(PathBuf::from(html_path), "public")?;
let html_path = file_writer::add_to_beginning(
PathBuf::from(html_path),
config
.clone()
.global_config
.website
.output
.unwrap_or("public".to_owned()),
)?;
logger.log(LogLevel::DETAILER, format!("Writing {:?}", html_path));
if let Some(render) = renders.get(idx) {
file_writer::write_file(&html_path, render.clone(), opt.overwrite)?;
@ -125,11 +141,12 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
}
logger.log(LogLevel::INFO, "Copying resources");
if let Some(resources) = config.global_config.resources {
if let Some(resources) = config.global_config.resources.clone() {
for resource in resources.values() {
let path = Path::new(&resource.source);
if path.exists() {
match write_recursive_resource(
config.clone(),
path.to_path_buf(),
PathBuf::from(resource.source.clone()),
PathBuf::from(resource.destination.clone()),
@ -152,6 +169,7 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
}
fn write_recursive_resource(
config: Config,
resource_path: PathBuf,
source: PathBuf,
destination: PathBuf,
@ -162,6 +180,7 @@ fn write_recursive_resource(
match item {
Ok(item) => {
match write_recursive_resource(
config.clone(),
item.path(),
source.clone(),
destination.clone(),
@ -179,8 +198,14 @@ fn write_recursive_resource(
Ok(mut read_file) => {
let mut contents = String::new();
read_file.read_to_string(&mut contents)?;
let mut dest_path =
file_writer::add_to_beginning(destination.clone(), "public")?;
let mut dest_path = file_writer::add_to_beginning(
destination.clone(),
config
.global_config
.website
.output
.unwrap_or("public".to_owned()),
)?;
if source.is_dir() {
dest_path = dest_path.join(relative.clone());

View File

@ -10,7 +10,7 @@ pub struct SinglePageConfigs {
pub page_config_path: PathBuf,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Config {
pub global_config: GlobalConfigToml,
pub page_config_paths: Vec<PathBuf>,

View File

@ -42,6 +42,8 @@ pub struct WebsiteConfig {
pub meta_description: Option<bool>,
pub charset: Option<String>,
pub meta_og: Option<bool>,
pub output: Option<String>,
}
#[derive(Deserialize, Serialize, Clone, Debug)]

View File

@ -113,6 +113,8 @@ fn run() -> Result<(), ()> {
meta_description: None,
charset: Some("utf-8".to_owned()),
meta_og: None,
output: None,
},
navbar: navbar,
resources: None,