wip: Render statics and styles
This commit is contained in:
parent
5078dee038
commit
07b6708d30
46
src/site.rs
46
src/site.rs
|
@ -9,7 +9,7 @@ use std::{
|
|||
};
|
||||
|
||||
use snafu::{ensure, ResultExt, Snafu};
|
||||
use tracing::{debug, info, info_span, warn};
|
||||
use tracing::{debug, info, info_span, trace, warn};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use self::{config::Config, page::Page, post::Post};
|
||||
|
@ -302,6 +302,40 @@ impl Site {
|
|||
let output_dir = output_dir.as_ref();
|
||||
let span = info_span!("Site::render", ?site_dir, ?output_dir);
|
||||
let _enter = span.enter();
|
||||
// Render the static files and styles
|
||||
let mut static_paths: Vec<PathBuf> = Vec::new();
|
||||
static_paths.extend(
|
||||
self.statics
|
||||
.iter()
|
||||
.map(|e| PathBuf::from("statics").join(e)),
|
||||
);
|
||||
static_paths.extend(self.styles.iter().map(|e| PathBuf::from("styles").join(e)));
|
||||
for static_path in static_paths {
|
||||
let from_path = site_dir.join(&static_path);
|
||||
let to_path = output_dir.join(&static_path);
|
||||
// Check to see if the parent directory exists
|
||||
if let Some(to_parent) = to_path.parent() {
|
||||
// Create it if it doesn't exist
|
||||
if !to_parent.try_exists().context(StaticFileCopySnafu {
|
||||
path_from: &from_path,
|
||||
path_to: &to_path,
|
||||
})? {
|
||||
debug!(?to_path, ?to_parent, "Creating directory");
|
||||
create_dir_all(to_parent).context(StaticFileCopySnafu {
|
||||
path_from: &from_path,
|
||||
path_to: &to_path,
|
||||
})?;
|
||||
}
|
||||
// Now copy the file
|
||||
trace!(?from_path, ?to_path, "Copying static file");
|
||||
std::fs::copy(&from_path, &to_path).context(StaticFileCopySnafu {
|
||||
path_from: &from_path,
|
||||
path_to: &to_path,
|
||||
})?;
|
||||
} else {
|
||||
warn!(?from_path, ?to_path, "To path had no parent?");
|
||||
}
|
||||
}
|
||||
todo!("Site::render stub")
|
||||
}
|
||||
}
|
||||
|
@ -419,4 +453,14 @@ pub enum SiteError {
|
|||
/// The list of possible canidates
|
||||
configs: Vec<PathBuf>,
|
||||
},
|
||||
/// Error copying a static file
|
||||
#[snafu(display("Errory copying {:?} to {:?}", path_from, path_to))]
|
||||
StaticFileCopy {
|
||||
/// The path being copied from
|
||||
path_from: PathBuf,
|
||||
/// The path being copied to
|
||||
path_to: PathBuf,
|
||||
/// The underlying error
|
||||
source: std::io::Error,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue