mirror of
https://github.com/zyllian/webdog.git
synced 2025-01-18 03:32:21 -08:00
make SiteBuilder
creation fallible
This commit is contained in:
parent
f4a2708794
commit
190cba1f3a
3 changed files with 6 additions and 7 deletions
|
@ -54,7 +54,7 @@ pub struct SiteBuilder {
|
|||
|
||||
impl SiteBuilder {
|
||||
/// Creates a new site builder.
|
||||
pub fn new(site: Site, serving: bool) -> Self {
|
||||
pub fn new(site: Site, serving: bool) -> eyre::Result<Self> {
|
||||
let mut build_path = match &site.config.build {
|
||||
Some(build) => site.site_path.join(build),
|
||||
_ => site.site_path.join("build"),
|
||||
|
@ -68,11 +68,10 @@ impl SiteBuilder {
|
|||
.join(format!("{}/**/*.tera", crate::TEMPLATES_PATH))
|
||||
.to_str()
|
||||
.expect("failed to convert path to string"),
|
||||
)
|
||||
.expect("failed to create tera instance");
|
||||
)?;
|
||||
tera.autoescape_on(vec![".tera"]);
|
||||
|
||||
Self {
|
||||
Ok(Self {
|
||||
tera,
|
||||
syntax_set: SyntaxSet::load_defaults_newlines(),
|
||||
theme_set: ThemeSet::load_defaults(),
|
||||
|
@ -80,7 +79,7 @@ impl SiteBuilder {
|
|||
site,
|
||||
build_path,
|
||||
serving,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Prepares the site builder for use and sets up the build directory.
|
||||
|
|
|
@ -159,7 +159,7 @@ impl Site {
|
|||
|
||||
/// Builds the site once.
|
||||
pub fn build_once(self) -> eyre::Result<()> {
|
||||
let builder = SiteBuilder::new(self, false).prepare()?;
|
||||
let builder = SiteBuilder::new(self, false)?.prepare()?;
|
||||
|
||||
builder.site.build_all_pages(&builder)?;
|
||||
builder.build_sass()?;
|
||||
|
|
|
@ -150,7 +150,7 @@ impl Site {
|
|||
pub async fn serve(self) -> eyre::Result<()> {
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
|
||||
|
||||
let mut builder = SiteBuilder::new(self, true).prepare()?;
|
||||
let mut builder = SiteBuilder::new(self, true)?.prepare()?;
|
||||
let site = &builder.site;
|
||||
let build_path = builder.build_path.clone();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue