]> git.r.bdr.sh - rbdr/blog/blame - src/generator/static_files.rs
Add generator
[rbdr/blog] / src / generator / static_files.rs
CommitLineData
29982470
RBR
1use std::fs::{copy, create_dir_all, read_dir};
2use std::io::Result;
3use std::path::PathBuf;
f6a545b0 4use crate::template::TemplateContext;
29982470
RBR
5
6fn recursively_copy(source: &PathBuf, target: &PathBuf) -> Result<()> {
7 let entries = read_dir(source)?;
8 for entry in entries {
9 let entry = entry?;
10 let entry_type = entry.file_type()?;
11 let entry_name = entry.file_name();
12 let entry_source = entry.path();
13 let entry_target = target.join(entry_name);
14
15 if entry_type.is_dir() {
16 create_dir_all(&entry_target)?;
17 recursively_copy(&entry_source, &entry_target)?;
18 } else {
19 copy(&entry_source, &entry_target)?;
20 }
21 }
22
23 Ok(())
24}
25
f6a545b0 26pub fn generate(source: &PathBuf, _: &PathBuf, target: &PathBuf, _: &TemplateContext) -> Result<()> {
29982470
RBR
27 if source.exists() {
28 return recursively_copy(source, target)
29 }
30 Ok(())
31}