Make add_to_beginning better
This commit is contained in:
parent
c3da02b2a1
commit
316ec09319
@ -14,6 +14,8 @@ mobile_viewport = true
|
|||||||
meta_description = true
|
meta_description = true
|
||||||
meta_og = true
|
meta_og = true
|
||||||
|
|
||||||
|
output = "public"
|
||||||
|
|
||||||
[google]
|
[google]
|
||||||
google_robots = "all"
|
google_robots = "all"
|
||||||
google_site_verification = "some_verification"
|
google_site_verification = "some_verification"
|
||||||
@ -39,4 +41,4 @@ link = "https://google.com"
|
|||||||
|
|
||||||
[resource.test]
|
[resource.test]
|
||||||
source = "test_page/resources/copied_resources/"
|
source = "test_page/resources/copied_resources/"
|
||||||
destination = "stuff_folder"
|
destination = ""
|
@ -41,7 +41,7 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
|||||||
.website
|
.website
|
||||||
.output
|
.output
|
||||||
.unwrap_or("public".to_owned()),
|
.unwrap_or("public".to_owned()),
|
||||||
)?;
|
);
|
||||||
logger.log(LogLevel::DETAIL, format!("Adding {:?}", css_path));
|
logger.log(LogLevel::DETAIL, format!("Adding {:?}", css_path));
|
||||||
file_writer::write_file(&css_path, DEFAULT_CSS, opt.overwrite)?;
|
file_writer::write_file(&css_path, DEFAULT_CSS, opt.overwrite)?;
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
|||||||
.website
|
.website
|
||||||
.output
|
.output
|
||||||
.unwrap_or("public".to_owned()),
|
.unwrap_or("public".to_owned()),
|
||||||
)?;
|
);
|
||||||
logger.log(LogLevel::DETAILER, format!("Writing {:?}", html_path));
|
logger.log(LogLevel::DETAILER, format!("Writing {:?}", html_path));
|
||||||
if let Some(render) = renders.get(idx) {
|
if let Some(render) = renders.get(idx) {
|
||||||
file_writer::write_file(&html_path, render.clone(), opt.overwrite)?;
|
file_writer::write_file(&html_path, render.clone(), opt.overwrite)?;
|
||||||
@ -145,11 +145,19 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
|||||||
for resource in resources.values() {
|
for resource in resources.values() {
|
||||||
let path = Path::new(&resource.source);
|
let path = Path::new(&resource.source);
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
|
let dest = file_writer::add_to_beginning(
|
||||||
|
PathBuf::from(resource.destination.clone()),
|
||||||
|
config
|
||||||
|
.clone()
|
||||||
|
.global_config
|
||||||
|
.website
|
||||||
|
.output
|
||||||
|
.unwrap_or("public".to_owned()),
|
||||||
|
);
|
||||||
match write_recursive_resource(
|
match write_recursive_resource(
|
||||||
config.clone(),
|
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
PathBuf::from(resource.source.clone()),
|
PathBuf::from(resource.source.clone()),
|
||||||
PathBuf::from(resource.destination.clone()),
|
dest,
|
||||||
) {
|
) {
|
||||||
Ok(_) => logger.log(LogLevel::DETAIL, "Resource successfully copied."),
|
Ok(_) => logger.log(LogLevel::DETAIL, "Resource successfully copied."),
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
@ -169,7 +177,6 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_recursive_resource(
|
fn write_recursive_resource(
|
||||||
config: Config,
|
|
||||||
resource_path: PathBuf,
|
resource_path: PathBuf,
|
||||||
source: PathBuf,
|
source: PathBuf,
|
||||||
destination: PathBuf,
|
destination: PathBuf,
|
||||||
@ -180,7 +187,6 @@ fn write_recursive_resource(
|
|||||||
match item {
|
match item {
|
||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
match write_recursive_resource(
|
match write_recursive_resource(
|
||||||
config.clone(),
|
|
||||||
item.path(),
|
item.path(),
|
||||||
source.clone(),
|
source.clone(),
|
||||||
destination.clone(),
|
destination.clone(),
|
||||||
@ -198,14 +204,7 @@ fn write_recursive_resource(
|
|||||||
Ok(mut read_file) => {
|
Ok(mut read_file) => {
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
read_file.read_to_string(&mut contents)?;
|
read_file.read_to_string(&mut contents)?;
|
||||||
let mut dest_path = file_writer::add_to_beginning(
|
let mut dest_path = destination.clone();
|
||||||
destination.clone(),
|
|
||||||
config
|
|
||||||
.global_config
|
|
||||||
.website
|
|
||||||
.output
|
|
||||||
.unwrap_or("public".to_owned()),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if source.is_dir() {
|
if source.is_dir() {
|
||||||
dest_path = dest_path.join(relative.clone());
|
dest_path = dest_path.join(relative.clone());
|
||||||
|
@ -9,16 +9,8 @@ use toml;
|
|||||||
use error::Error;
|
use error::Error;
|
||||||
use logger::LogLevel;
|
use logger::LogLevel;
|
||||||
|
|
||||||
pub fn add_to_beginning<T: Into<String>>(path: PathBuf, to_add: T) -> Result<PathBuf, Error> {
|
pub fn add_to_beginning<T: Into<String>>(path: PathBuf, to_add: T) -> PathBuf {
|
||||||
if let (Some(parent), Some(file_name)) = (path.clone().parent(), path.clone().file_name()) {
|
Path::new(&to_add.into()).join(path)
|
||||||
let parent = Path::new(&to_add.into()).join(parent);
|
|
||||||
Ok(parent.join(file_name))
|
|
||||||
} else {
|
|
||||||
return Err(Error::new(
|
|
||||||
LogLevel::SEVERE,
|
|
||||||
format!("Could not find parent folder or file name for {:?}", path),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_toml<T: Serialize>(path: &PathBuf, data: &T, overwrite: bool) -> Result<(), Error> {
|
pub fn write_toml<T: Serialize>(path: &PathBuf, data: &T, overwrite: bool) -> Result<(), Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user