From aa35459819dcf3bef69550abbc624696a99bc6b8 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Fri, 17 Mar 2023 17:23:37 -0400 Subject: [PATCH] feat: Add statics directory to init --- src/site.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/site.rs b/src/site.rs index ebd39ae..385134a 100644 --- a/src/site.rs +++ b/src/site.rs @@ -98,6 +98,10 @@ pub struct Site { pub pages: HashMap, /// Posts pub posts: HashMap, + /// Static content + /// + /// Path is relative to `statics` directory + pub statics: Vec, } impl Default for Site { @@ -110,6 +114,7 @@ impl Default for Site { config: Config::default(), pages, posts, + statics: Vec::new(), } } } @@ -154,6 +159,23 @@ impl Site { post.write(site_dir, post_path) .context(PostWriteSnafu { post: post_path })?; } + // Make sure the statics directory exists + let statics_dir = site_dir.join("statics"); + if statics_dir + .try_exists() + .context(ExistanceCheckSnafu { path: &statics_dir })? + { + ensure!( + statics_dir.is_dir(), + NotADirectorySnafu { path: &statics_dir } + ); + } else { + // Create the directory + create_dir_all(&statics_dir).context(CreateDirectorySnafu { path: &statics_dir })?; + // Touch a .gitkeep + let git_keep = statics_dir.join(".gitkeep"); + File::create(&git_keep).context(CreateDirectorySnafu { path: &git_keep })?; + } Ok(()) } }