hugo/content/en/hugo-pipes/fingerprint.md
Bjørn Erik Pedersen b9bd35d72e Squashed 'docs/' content from commit fdea5430f
git-subtree-dir: docs
git-subtree-split: fdea5430f89dfd849d39212abdf5ace0a4763e5a
2019-10-21 10:22:28 +02:00

1.1 KiB
Executable file

title description date publishdate lastmod categories keywords menu weight sections_weight draft
Fingerprinting and SRI Hugo Pipes allows Fingerprinting and Subresource Integrity. 2018-07-14 2018-07-14 2018-07-14
asset management
docs
parent weight
pipes 70
70 70 false

Fingerprinting and SRI can be applied to any asset file using resources.Fingerprint which takes two arguments, the resource object and a hash function.

The default hash function is sha256. Other available functions are sha384 (from Hugo 0.55), sha512 and md5.

Any so processed asset will bear a .Data.Integrity property containing an integrity string, which is made up of the name of the hash function, one hyphen and the base64-encoded hash sum.

{{ $js := resources.Get "js/global.js" }}
{{ $secureJS := $js | resources.Fingerprint "sha512" }}
<script type="text/javascript" src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>