From 13e8c99e6047579fe99a39790690495232da5785 Mon Sep 17 00:00:00 2001 From: Zoey Date: Thu, 19 Aug 2021 14:09:13 -0700 Subject: [PATCH] Copy files to root on initial build --- site/root/CNAME | 1 + src/builder.rs | 11 ++++++++++- src/lib.rs | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 site/root/CNAME diff --git a/site/root/CNAME b/site/root/CNAME new file mode 100644 index 0000000..f358492 --- /dev/null +++ b/site/root/CNAME @@ -0,0 +1 @@ +zoey.dev diff --git a/src/builder.rs b/src/builder.rs index f5a26c8..2be829b 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -11,7 +11,7 @@ use pulldown_cmark::{Options, Parser}; use serde::Serialize; use walkdir::WalkDir; -use crate::{util, PageMetadata, Site, SASS_PATH, STATIC_PATH}; +use crate::{util, PageMetadata, Site, ROOT_PATH, SASS_PATH, STATIC_PATH}; /// Struct containing data to be sent to templates when rendering them. #[derive(Debug, Serialize)] @@ -83,6 +83,15 @@ impl<'a> SiteBuilder<'a> { .context("Failed to register template file")?; } + let root_path = self.site.site_path.join(ROOT_PATH); + if root_path.exists() { + for entry in root_path.read_dir()? { + let entry = entry?; + let path = entry.path(); + std::fs::copy(&path, self.build_path.join(path.strip_prefix(&root_path)?))?; + } + } + let static_path = self.site.site_path.join(STATIC_PATH); if static_path.exists() { fs_extra::copy_items( diff --git a/src/lib.rs b/src/lib.rs index 02fd1f4..ef6afaf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ const PAGES_PATH: &str = "pages"; const TEMPLATES_PATH: &str = "templates"; const STATIC_PATH: &str = "static"; const SASS_PATH: &str = "sass"; +const ROOT_PATH: &str = "root"; /// Struct for the site's configuration. #[derive(Debug, Deserialize)]