I would refactor this whole thing.
site config
params:
cdn:
jxl:
decoder:
remoteURL: 'https://cdn.jsdelivr.net/gh/niutech/jxl.js/jxl_dec.js'
localURL: js/jxl_dec.js
loader:
remoteURL: 'https://cdn.jsdelivr.net/gh/niutech/jxl.js/jxl.min.js'
localURL: js/jxl.js
wasm:
remoteURL: 'https://cdn.jsdelivr.net/gh/niutech/jxl.js/jxl_dec.wasm'
localURL: wasm/jxl_dec.wasm
template
{{ range site.Params.cdn.jxl }}
{{ $remoteURL := .remoteURL }}
{{ $localURL := .localURL }}
{{ with resources.GetRemote $remoteURL }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ with resources.Copy $localURL . }}
{{ .Publish }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $remoteURL }}
{{ end }}
{{ end }}
rendered
public/
├── js/
│ ├── jxl_dec.js
│ └── jxl.js
├── posts/
│ ├── post-1/
│ │ └── index.html
│ └── index.html
├── wasm/
│ └── jxl_dec.wasm
├── favicon.ico
└── index.html