Fingerprint json in static

Not a complicated question here.

I need to fingerprint json files in static before passing their names into js.Build, or into a script tag where JavaScript can get them.

So put them in a folder in data and pull them in from there.

Okay yes, but there are many of them, and a pipeline producing them, and I do not have time at the moment to deal with that, any suggestions?

Perhaps, but not terribly clear either.

Typically you would place these files in assets/something, then capture each as a resource (in a loop if you want) and either pass them through fingerprint or create your own fingerprint by hashing .Content then using resources.Copy to copy to a new location.

A work in progress, resources/something over data/something?

Once you’ve captured a global resource with resource.Get, resources.GetMatch, resources.Match, or resources.ByType you can access its content with the .Content method, pass it though the resources.Fingerprint function, pass it through resources.Copy function, etc. It’s much more flexible, and idiomatic (i.e., the standard/recommended way to accomplish something).

Well, I just tried it several times, and I can confirm: it’s better to capture “a global resource
with resource.Get, resources.GetMatch, resources.Match, or resources.ByType

Thanks, I know it’s a grind, but I never would have seen that.

Having said that, you’re saying:

{{- with resources.Get (printf `%s%s` "dir_in_assets/dir_group/" $jsonFileName )   -}}

{{ with resources.Copy (printf `%s%s` "dir_group_in_static/" $jsonFileName)  ( . | minify | fingerprint "sha256") }}

<!-- test -->

<p>Site context json file is: {{- .Permalink -}}</p>

<!-- pass url string to javascript here -->
{{- end -}}
{{- end -}}

Then .Content comes into play only when you want to print the content to a script tag. And just like in a link tag, an href gets a fingerprint on the end.

Then can I see a hash on the end of the permalink in the paragraph tag, to pass the fingerprinted url into JavaScript?

[Edit: the code here solves the problem]

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.