From 4d1d5308d3d83a23f9de2cd892c04874e6a231d2 Mon Sep 17 00:00:00 2001 From: zyl Date: Fri, 14 Jun 2024 22:01:05 -0700 Subject: [PATCH] implement support for directories in the static file structure --- src/builder.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index c470c8f..1a024b1 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -95,10 +95,16 @@ impl<'a> SiteBuilder<'a> { let root_path = self.site.site_path.join(ROOT_PATH); if root_path.exists() { - for entry in root_path.read_dir()? { + for entry in walkdir::WalkDir::new(&root_path) { let entry = entry?; let path = entry.path(); - std::fs::copy(&path, self.build_path.join(path.strip_prefix(&root_path)?))?; + if path.is_dir() { + continue; + } + let output_path = self.build_path.join(path.strip_prefix(&root_path)?); + let parent_path = output_path.parent().expect("should never fail"); + std::fs::create_dir_all(parent_path)?; + std::fs::copy(path, output_path)?; } }