sha256 function

Currently their are the md5 and sha1 functions. It would be great if SHA256 were also supported.

Because then combined with the base64 and readFile functions, the integrity html attribute could be used.

Example:

<script src="/behaviour.js" integrity="sha256-{{ (sha256 (readFile "static/behaviour.js")) | base64Encode }}"></script>

A sha256 func pull request is welcomed – but note that without any caching, adding that script definition to a partial that is included in every template will be veeeery heavy in the performance department.

I submitted a pull request that is already merged.

To anyone who has searched for the integrity attribute:

Note that the above example will work, but won’t be valid.
The sha256 function outputs a hexadecimal value, but what is needed, is binary.

The documentation clearly states that the return value will be a checksum, instead of a digest. Excuse the noise.

Interesting. I think a better approach is to write a tool that creates an integrity-manifest.json and puts it into the /data/ directory so that Hugo can access it that way. It prevents you’re needing to recalculate for every page, as BEP noted is a drawback of having it in the template.