feat: Add statics directory to init
This commit is contained in:
parent
76fe128587
commit
aa35459819
22
src/site.rs
22
src/site.rs
|
@ -98,6 +98,10 @@ pub struct Site {
|
||||||
pub pages: HashMap<PathBuf, Page>,
|
pub pages: HashMap<PathBuf, Page>,
|
||||||
/// Posts
|
/// Posts
|
||||||
pub posts: HashMap<PathBuf, Post>,
|
pub posts: HashMap<PathBuf, Post>,
|
||||||
|
/// Static content
|
||||||
|
///
|
||||||
|
/// Path is relative to `statics` directory
|
||||||
|
pub statics: Vec<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Site {
|
impl Default for Site {
|
||||||
|
@ -110,6 +114,7 @@ impl Default for Site {
|
||||||
config: Config::default(),
|
config: Config::default(),
|
||||||
pages,
|
pages,
|
||||||
posts,
|
posts,
|
||||||
|
statics: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,6 +159,23 @@ impl Site {
|
||||||
post.write(site_dir, post_path)
|
post.write(site_dir, post_path)
|
||||||
.context(PostWriteSnafu { post: 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue