mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
a3535c8486
a4fa0d1d6 Typos and grammatical changes 513884600 Add hugo pipes documentation git-subtree-dir: docs git-subtree-split: a4fa0d1d641b2b3e27a91ae8b1a0a29be3c42ddf
29 lines
No EOL
1.1 KiB
Markdown
Executable file
29 lines
No EOL
1.1 KiB
Markdown
Executable file
---
|
|
title: Fingerprinting and SRI
|
|
description: Hugo Pipes allows Fingerprinting and Subresource Integrity.
|
|
date: 2018-07-14
|
|
publishdate: 2018-07-14
|
|
lastmod: 2018-07-14
|
|
categories: [asset management]
|
|
keywords: []
|
|
menu:
|
|
docs:
|
|
parent: "pipes"
|
|
weight: 70
|
|
weight: 70
|
|
sections_weight: 70
|
|
draft: false
|
|
---
|
|
|
|
|
|
Fingerprinting and [SRI](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) can be applied to any asset file using `resources.Fingerpint` which takes two arguments, the resource object and a [hash function](https://en.wikipedia.org/wiki/Cryptographic_hash_function).
|
|
|
|
The default hash function is `sha256`. Other available functions are `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.
|
|
|
|
```go-html-template
|
|
{{ $js := resources.Get "js/global.js" }}
|
|
{{ $secureJS := $js | resources.Fingerprint "sha512" }}
|
|
<script type="text/javascript" src="{{ $secureJS.Permalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>
|
|
``` |