How to set JS asset target name/path?

For my SCSS pipeline I wrote the following little template:

{{- $scss := resources.Get "scss/_index.scss" -}}
{{- $css_path := printf "css/theme-%s.css" (md5 $scss) -}}
{{- $options := (dict "targetPath" $css_path "outputStyle" "compressed") -}}
{{- $css := $scss | toCSS $options -}}
<link rel="stylesheet" href="{{ $css.RelPermalink }}">

How would I do that (specifically line 2) with a JS asset? The targetPath feature looks to be from the SCSS pipeline only.

I don’t think you need to do that (depending on your final goal, of course).

In my theme I have code like:

{{ $jsFile := resources.Get "assets/js/site.js" | minify | fingerprint "md5" }}

When I then call {{ $jsFile.RelPermalink }} in my template, I already get the asset URL with the MD5 hash. So I don’t have to explicitly construct that target path location myself.

For instance:

<script async src=/assets/js/site.d0314e9db82fbe48eb66d935404bf6fd.js></script>

Is that the kind of URL you’re after, or do I misunderstand? :slight_smile:


Yes, that’s what I was after! I ran into fingerprint but thought that it only generated an “Integrity” string (which isn’t URL-friendly) without modifying the input. I stand corrected, thanks! :slightly_smiling_face:

1 Like