mirror of
https://github.com/getzola/zola
synced 2024-11-10 06:14:19 +00:00
Refactor: copy_assets instead of copy_asset (#2418)
This commit is contained in:
parent
7fb0a70477
commit
bdb18657b6
1 changed files with 15 additions and 24 deletions
|
@ -676,8 +676,19 @@ impl Site {
|
|||
Ok(current_path)
|
||||
}
|
||||
|
||||
fn copy_asset(&self, src: &Path, dest: &Path) -> Result<()> {
|
||||
copy_file_if_needed(src, dest, self.config.hard_link_static)
|
||||
fn copy_assets(&self, parent: &Path, assets: &[impl AsRef<Path>], dest: &Path) -> Result<()> {
|
||||
for asset in assets {
|
||||
let asset_path = asset.as_ref();
|
||||
copy_file_if_needed(
|
||||
asset_path,
|
||||
&dest.join(
|
||||
asset_path.strip_prefix(parent).expect("Couldn't get filename from page asset"),
|
||||
),
|
||||
self.config.hard_link_static,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Renders a single content page
|
||||
|
@ -689,17 +700,7 @@ impl Site {
|
|||
self.write_content(&components, "index.html", content, !page.assets.is_empty())?;
|
||||
|
||||
// Copy any asset we found previously into the same directory as the index.html
|
||||
for asset in &page.assets {
|
||||
let asset_path = asset.as_path();
|
||||
self.copy_asset(
|
||||
asset_path,
|
||||
¤t_path.join(
|
||||
asset_path
|
||||
.strip_prefix(page.file.path.parent().unwrap())
|
||||
.expect("Couldn't get filename from page asset"),
|
||||
),
|
||||
)?;
|
||||
}
|
||||
self.copy_assets(page.file.path.parent().unwrap(), &page.assets, ¤t_path)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1082,17 +1083,7 @@ impl Site {
|
|||
}
|
||||
|
||||
// Copy any asset we found previously into the same directory as the index.html
|
||||
for asset in §ion.assets {
|
||||
let asset_path = asset.as_path();
|
||||
self.copy_asset(
|
||||
asset_path,
|
||||
&output_path.join(
|
||||
asset_path
|
||||
.strip_prefix(section.file.path.parent().unwrap())
|
||||
.expect("Failed to get asset filename for section"),
|
||||
),
|
||||
)?;
|
||||
}
|
||||
self.copy_assets(§ion.file.path.parent().unwrap(), §ion.assets, &output_path)?;
|
||||
|
||||
if render_pages {
|
||||
section
|
||||
|
|
Loading…
Reference in a new issue