hugo/docs/content/en/hugo-pipes/fingerprint.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.2 KiB
Executable file

title linkTitle description categories keywords menu weight action
Fingerprint Fingerprinting and SRI hashing Process a given resource, adding a hash string of the resource's content.
asset management
docs
parent weight
hugo-pipes 100
100
aliases returnType signatures
fingerprint
resource.Resource
resources.Fingerprint [ALGORITHM] RESOURCE

Usage

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

The default hash algorithm is sha256. Other available algorithms are sha384 and (as of 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 algorithm, one hyphen and the base64-encoded hash sum.

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