Copy the images into the output.
This commit is contained in:
36
src/context/dependency.rs
Normal file
36
src/context/dependency.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::error::CustomError;
|
||||
|
||||
use super::RenderContext;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum Dependency {
|
||||
StaticFile { absolute_path: PathBuf },
|
||||
}
|
||||
|
||||
impl Dependency {
|
||||
pub(crate) async fn perform(
|
||||
&self,
|
||||
render_context: RenderContext<'_>,
|
||||
) -> Result<(), CustomError> {
|
||||
match self {
|
||||
Dependency::StaticFile { absolute_path } => {
|
||||
let input_root_directory = render_context.config.get_root_directory();
|
||||
let relative_path_to_file = absolute_path.strip_prefix(input_root_directory)?;
|
||||
let path_to_output = render_context
|
||||
.output_root_directory
|
||||
.join(relative_path_to_file);
|
||||
tokio::fs::create_dir_all(
|
||||
path_to_output
|
||||
.parent()
|
||||
.ok_or("Output file should have a containing directory.")?,
|
||||
)
|
||||
.await?;
|
||||
// TODO: If file already exists, either error out or compare hash to avoid duplicate write.
|
||||
tokio::fs::copy(absolute_path, path_to_output).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,4 +58,11 @@ impl DependencyManager {
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Return the dependencies and forget about them.
|
||||
pub(crate) fn take_dependencies(&mut self) -> Vec<Dependency> {
|
||||
let mut dependencies = Vec::new();
|
||||
std::mem::swap(&mut self.dependencies, &mut dependencies);
|
||||
dependencies
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user