Post Build Resource Transformations
It’s Eeaster, a time for mysteries and puzzles. And at first glance, this Hugo release looks a little mysterious. The core of if is a mind-twister:
{{ $css := resources.Get "css/main.css" }}
{{ $css = $css | resources.PostCSS }}
{{ if hugo.IsProduction }}
{{ $css = $css | minify | fingerprint | resources.PostProcess }}
{{ end }}
<link href="{{ $css.RelPermalink }}" rel="stylesheet" />
The above uses the new resources.PostProcess template function which tells Hugo to postpone the transformation of the Hugo Pipes chain to after the build, allowing the build steps to use the build output in /public
as part of its processing.
The prime current use case for the above is CSS pruning in PostCSS. In simple cases you can use the templates as a base for the content filters, but that has its limitations and can be very hard to setup, especially in themed configurations. So we have added a new writeStats configuration that, when enabled, will write a file named hugo_stats.json
to your project root with some aggregated data about the build, e.g. list of HTML entities published, to be used to do CSS pruning.
This release represents 20 contributions by 10 contributors to the main Hugo code base.@bep leads the Hugo development with a significant amount of contributions, but also a big shoutout to @moorereason, @jaywilliams, and @satotake for their ongoing contributions. And a big thanks to @digitalcraftsman and @onedrawingperday for their relentless work on keeping the themes site in pristine condition and to @davidsneighbour and @kaushalmodi for all the great work on the documentation site.
Many have also been busy writing and fixing the documentation in hugoDocs, which has received 14 contributions by 7 contributors. A special thanks to @bep, @coliff, @dmgawel, and @jasikpark for their work on the documentation site.
Hugo now has:
- 43052+ stars
- 438+ contributors
- 302+ themes
Enhancements
Templates
- Extend Jsonify to support options map 8568928a @moorereason
- Extend Jsonify to support optional indent parameter 1bc93021 @moorereason #5040
Other
- Regen docs helper b7ff4dc2 @bep
- Collect HTML elements during the build to use in PurgeCSS etc. 095bf64c @bep #6999
- Update to latest emoji package 7791a804 @QuLogic
- Update hosting-on-aws-amplify.md c774b230 @Helicer
- Add basic “post resource publish support” 2f721f8e @bep #7146
- Typo correction 7eba37ae @fekete-robert
- Use semver for min_version per recommendations efc61d6f @jaywilliams
- Updateto gitmap v1.1.2 4de3ecdc @dragtor #6985
- Add data context to the key in ExecuteAsTemplate" c9dc316a @bep #7064
Fixes
Other
- Fix hugo mod vendor for regular file mounts d8d6a25b @bep #7140
- Revert “Revert “common/herrors: Fix typos in comments”” 9f12be54 @bep
- Fix typos in comments" 4437e918 @bep
- Fix typos in comments 1123711b @rnazmo
- Fix TrimShortHTML 9c998753 @satotake #7081
- Fix IsDescendant/IsAncestor for overlapping section names 4a39564e @bep #7096
- fix typo in getting started b6e097cf @matrixise
- Fix _build.list.local logic 523d5194 @bep #7089
- Fix cache reset for a page’s collections on server live reload cfa73050 @bep #7085
Улучшить эту страницу