X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/0e276d039b8613de0cbd302bf328bb660ab063b6..2998247083406f914b3647cedd19abf5507bf2c6:/src/generator/static_files.rs?ds=inline diff --git a/src/generator/static_files.rs b/src/generator/static_files.rs new file mode 100644 index 0000000..6804800 --- /dev/null +++ b/src/generator/static_files.rs @@ -0,0 +1,31 @@ +use std::fs::{copy, create_dir_all, read_dir}; +use std::io::Result; +use std::path::PathBuf; +use crate::post::Post; + +fn recursively_copy(source: &PathBuf, target: &PathBuf) -> Result<()> { + let entries = read_dir(source)?; + for entry in entries { + let entry = entry?; + let entry_type = entry.file_type()?; + let entry_name = entry.file_name(); + let entry_source = entry.path(); + let entry_target = target.join(entry_name); + + if entry_type.is_dir() { + create_dir_all(&entry_target)?; + recursively_copy(&entry_source, &entry_target)?; + } else { + copy(&entry_source, &entry_target)?; + } + } + + Ok(()) +} + +pub fn generate(source: &PathBuf, _: &PathBuf, target: &PathBuf, _: &Vec) -> Result<()> { + if source.exists() { + return recursively_copy(source, target) + } + Ok(()) +}