Skip to content

Commit c1b6c66

Browse files
committed
feat: add data-target-path to the icon step
1 parent 106863c commit c1b6c66

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

site/content/assets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ This will typically look like: `<link data-trunk rel="{type}" href="{path}" ..ot
6969
`rel="icon"`: Trunk will copy the icon image specified in the `href` attribute to the `dist` dir. This content is hashed for cache control.
7070

7171
- `data-integrity`: (optional) the `integrity` digest type for code & script resources. Defaults to plain `sha384`.
72+
- `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 `..`.
7273

7374
## inline
7475

src/pipelines/icon.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Icon asset pipeline.
22
33
use super::{AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_HREF};
4+
use crate::common::target_path;
45
use crate::config::RtcBuild;
56
use crate::pipelines::{AssetFileType, ImageType};
67
use crate::processing::integrity::{IntegrityType, OutputDigest};
@@ -21,6 +22,8 @@ pub struct Icon {
2122
asset: AssetFile,
2223
/// The required integrity setting
2324
integrity: IntegrityType,
25+
/// Optional target path inside the dist dir.
26+
target_path: Option<PathBuf>,
2427
}
2528

2629
impl Icon {
@@ -42,11 +45,17 @@ impl Icon {
4245

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

48+
let target_path = attrs
49+
.get("data-target-path")
50+
.map(|val| val.parse())
51+
.transpose()?;
52+
4553
Ok(Self {
4654
id,
4755
cfg,
4856
asset,
4957
integrity,
58+
target_path,
5059
})
5160
}
5261

@@ -66,17 +75,21 @@ impl Icon {
6675
"image/png" => ImageType::Png,
6776
_ => ImageType::Other,
6877
};
78+
79+
let result_dir =
80+
target_path(&self.cfg.staging_dist, self.target_path.as_deref(), None).await?;
81+
6982
let file = self
7083
.asset
7184
.copy(
72-
&self.cfg.staging_dist,
85+
&result_dir,
7386
self.cfg.filehash,
7487
self.cfg.release && !self.cfg.no_minification,
7588
AssetFileType::Icon(image_type),
7689
)
7790
.await?;
7891

79-
let result_file = self.cfg.staging_dist.join(&file);
92+
let result_file = result_dir.join(&file);
8093
let integrity = OutputDigest::generate(self.integrity, || std::fs::read(&result_file))
8194
.with_context(|| {
8295
format!(

0 commit comments

Comments
 (0)