feat: Add statics directory to init

This commit is contained in:
Nathan McCarty 2023-03-17 17:23:37 -04:00
parent 76fe128587
commit aa35459819
Signed by: thatonelutenist
GPG Key ID: D70DA3DD4D1E9F96
1 changed files with 22 additions and 0 deletions

View File

@ -98,6 +98,10 @@ pub struct Site {
pub pages: HashMap<PathBuf, Page>,
/// Posts
pub posts: HashMap<PathBuf, Post>,
/// Static content
///
/// Path is relative to `statics` directory
pub statics: Vec<PathBuf>,
}
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(())
}
}