I am minimizing a .json page resource that get’s consumed by javascript on the page. That bit is working as expected in dev. But when I use the path to the minified resource (RelPermalink) in order ensure that it gets written to disk, the path becomes absolute.
In my config:
baseURL: ""
relativeURLs: true
(I’m deploying to an environment where the directory changes w/ each deployment, so baseURL CANNOT be used.)
What I would like to see is <div class="question" data-dataFile="data.min.json">
. But instead I get <div class="question" data-dataFile="/section/subsection/page/data.min.json">
.
{{ $jsonMin := "" }}
{{ range $jsonPathRes := .Page.Resources.Match ("*.json") }}
{{ if eq $jsonPathRes.Name "data.json" }}
{{ $jsonMin = $jsonPathRes | resources.Minify }}
{{ end }}
{{ end }}
<div class="question" data-dataFile="{{$jsonMin.RelPermalink}}"></div>
What does work is simply lopping off the entire folder structure (data-dataFile="{{path.Base $jsonMin.RelPermalink}}"
). But this feels brittle.
Is there a way (other than RelPermalink) to calculate a relative path to an asset, given a base url?