Skip to content

Commit

Permalink
feat: add data-target-path to the icon step
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Feb 28, 2024
1 parent 106863c commit c1b6c66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions site/content/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ This will typically look like: `<link data-trunk rel="{type}" href="{path}" ..ot
`rel="icon"`: Trunk will copy the icon image specified in the `href` attribute to the `dist` dir. This content is hashed for cache control.

- `data-integrity`: (optional) the `integrity` digest type for code & script resources. Defaults to plain `sha384`.
- `data-target-path`: (optional) Path where the directory is placed inside the dist dir. If not present the directory is placed in the dist root. The path must be a relative path without `..`.

## inline

Expand Down
17 changes: 15 additions & 2 deletions src/pipelines/icon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Icon asset pipeline.
use super::{AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_HREF};
use crate::common::target_path;
use crate::config::RtcBuild;
use crate::pipelines::{AssetFileType, ImageType};
use crate::processing::integrity::{IntegrityType, OutputDigest};
Expand All @@ -21,6 +22,8 @@ pub struct Icon {
asset: AssetFile,
/// The required integrity setting
integrity: IntegrityType,
/// Optional target path inside the dist dir.
target_path: Option<PathBuf>,
}

impl Icon {
Expand All @@ -42,11 +45,17 @@ impl Icon {

let integrity = IntegrityType::from_attrs(&attrs, &cfg)?;

let target_path = attrs
.get("data-target-path")
.map(|val| val.parse())
.transpose()?;

Ok(Self {
id,
cfg,
asset,
integrity,
target_path,
})
}

Expand All @@ -66,17 +75,21 @@ impl Icon {
"image/png" => ImageType::Png,
_ => ImageType::Other,
};

let result_dir =
target_path(&self.cfg.staging_dist, self.target_path.as_deref(), None).await?;

let file = self
.asset
.copy(
&self.cfg.staging_dist,
&result_dir,
self.cfg.filehash,
self.cfg.release && !self.cfg.no_minification,
AssetFileType::Icon(image_type),
)
.await?;

let result_file = self.cfg.staging_dist.join(&file);
let result_file = result_dir.join(&file);
let integrity = OutputDigest::generate(self.integrity, || std::fs::read(&result_file))
.with_context(|| {
format!(
Expand Down

0 comments on commit c1b6c66

Please # to comment.