Copy the images into the output.

This commit is contained in:
Tom Alexander
2025-02-08 19:46:46 -05:00
parent bf7f37260c
commit 59ee13345e
3 changed files with 68 additions and 13 deletions

36
src/context/dependency.rs Normal file
View 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(())
}
}
}
}

View File

@@ -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
}
}