summaryrefslogtreecommitdiffstats
path: root/minifiers
AgeCommit message (Collapse)Author
2024-01-28all: Run gofumpt -l -w .Bjørn Erik Pedersen
2024-01-27all: Rework page store, add a dynacache, improve partial rebuilds, and some ↵develop2024Bjørn Erik Pedersen
general spring cleaning There are some breaking changes in this commit, see #11455. Closes #11455 Closes #11549 This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build. The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate. A list of the notable new features: * A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server. * A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently. * You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs. We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections). Memory Limit * Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory. New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively. This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive): Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers. Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds. Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role). Fixes #10169 Fixes #10364 Fixes #10482 Fixes #10630 Fixes #10656 Fixes #10694 Fixes #10918 Fixes #11262 Fixes #11439 Fixes #11453 Fixes #11457 Fixes #11466 Fixes #11540 Fixes #11551 Fixes #11556 Fixes #11654 Fixes #11661 Fixes #11663 Fixes #11664 Fixes #11669 Fixes #11671 Fixes #11807 Fixes #11808 Fixes #11809 Fixes #11815 Fixes #11840 Fixes #11853 Fixes #11860 Fixes #11883 Fixes #11904 Fixes #7388 Fixes #7425 Fixes #7436 Fixes #7544 Fixes #7882 Fixes #7960 Fixes #8255 Fixes #8307 Fixes #8863 Fixes #8927 Fixes #9192 Fixes #9324
2024-01-25deps: Update github.com/tdewolff/minify/v2 v2.20.9 => v2.20.13James Tatum
KeepConditionalComments was deprecated in the upstream library and replaced with KeepSpecialComments. This new option reflects that both conditional comments and Server Side Include comments can be optionally stripped by the minifier. As with KeepConditionalComments, the minifier is configured not to strip them by default.
2023-08-07Add all config to docshelper.jsonBjørn Erik Pedersen
Also consolidate so the mediaTypes and outputFormats are listed once only. Fixes #11328
2023-05-24minifiers: Make sure JS.Version always has a valueBjørn Erik Pedersen
Fixes #11012
2023-05-16Create a struct with all of Hugo's config optionsBjørn Erik Pedersen
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
2022-05-27deps: Update to github.com/tdewolff/minify/v2 v2.11.5Bjørn Erik Pedersen
2022-04-08deps: Update github.com/tdewolff/minify/v2 v2.10.0 => v2.11.0Joe Mooring
Fixes #9713 Fixes #9740 Adds support for minify.tdewolff.svg.keepComments (bool)
2022-04-08Rework the Destination filesystem to make --renderStaticToDisk workBjørn Erik Pedersen
See #9626
2022-03-17all: gofmt -w -r 'interface{} -> any' .Bjørn Erik Pedersen
Updates #9687
2022-03-09minifiers: Make keepWhitespace = false default for HTML (note)Joe Mooring
Closes #9456
2021-09-22Pass minification errors to the userPaul Gottschling
Previously, *minifyTransformation.Transform suppressed the error returned by t.m.Minify. This meant that when minification returned an error, the error would not reach the user. Instead, minification would silently fail. For example, if a JavaScript file included a call to the Date constructor with: new Date(2020, 04, 02) The package that the minification library uses to parse JS files, github.com/tdewolff/parse would return an error, since "04" would be parsed as a legacy octal. However, the JS file would remain un-minified with no error. Fixing this is not as simple as replacing "_" with an "err" in *minifyTransformation.Transform, however (though this is necessary). If we only returned this error from Transform, then hugolib.TestResourceMinifyDisabled would fail. Instead of being a no-op, as TestResourceMinifyDisabled expects, using the "minify" template function with a "disableXML=true" config setting instead returns the error, "minifier does not exist for mimetype." The "minifier does not exist" error is returned because of the way minifiers.New works. If the user's config disables minification for a particular MIME type, minifiers.New does not add it to the resulting Client's *minify.M. However, this also means that when the "minify" template function is executed, a *resourceAdapter's transformations still add a minification. When it comes time to call the minify.Minifier for a specific MIME type via *M.MinifyMimetype, the github.com/tdewolff/minify library throws the "does not exist" error for the missing MIME type. The solution was to change minifiers.New so, instead of skipping a minifier for each disabled MIME type, it adds a NoOpMinifier, which simply copies the source to the destination without minification. This means that when the "minify" template function is used for a particular resource, and that resource's MIME type has minification disabled, minification is genuinely skipped, and does not result in an error. In order to add this, I've fixed a possibly unwanted interaction between minifiers.TestConfigureMinify and hugolib.TestResourceMinifyDisabled. The latter disables minification and expects minification to be a no-op. The former disables minification and expects it to result in an error. The only reason hugolib.TestResourceMinifyDisabled passes in the original code is that the "does not exist" error is suppressed. However, we shouldn't suppress minification errors, since they can leave users perplexed. I've changed the test assertion in minifiers.TestConfigureMinify to expect no errors and a no-op if minification is disabled for a particular MIME type. Fixes #8954
2021-07-19minifiers: Make keepWhitespace = true default for HTMLBjørn Erik Pedersen
Fixes #8771
2021-06-18media: support application/manifest+jsonRohan Kumar
The standard file extension for Web App Manifest files is ".webmanifest". This commit allows Hugo to recognize .webmanifest files as "application/manifest+json" files and to minify them using its JSON minifier. The .webmanifest file extension is recommended in the w3c spec to simplify media type registration: https://www.w3.org/TR/appmanifest/#media-type-registration Webhint docs are also relevant: https://webhint.io/docs/user-guide/hints/hint-manifest-file-extension/ Closes #8624
2021-06-14Misc config loading fixesBjørn Erik Pedersen
The main motivation behind this is simplicity and correctnes, but the new small config library is also faster: ``` BenchmarkDefaultConfigProvider/Viper-16 252418 4546 ns/op 2720 B/op 30 allocs/op BenchmarkDefaultConfigProvider/Custom-16 450756 2651 ns/op 1008 B/op 6 allocs/op ``` Fixes #8633 Fixes #8618 Fixes #8630 Updates #8591 Closes #6680 Closes #5192
2021-03-20deps: Bump github.com/tdewolff/minify/v2 v2.9.15Bjørn Erik Pedersen
Fixes #8332
2021-02-18deps: Update github.com/tdewolff/minify/v2 v2.6.2 => v2.9.13Bjørn Erik Pedersen
Fixes #8258
2020-12-16all: Fix minor typosPhil Davis
2020-12-03all: Format code with gofumptBjørn Erik Pedersen
See https://github.com/mvdan/gofumpt
2020-10-07Revert "deps: Update to github.com/tdewolff/minify v2.9.4"Bjørn Erik Pedersen
Closes #7792 This reverts commit b254532b52785954c98a473a635b9cea016d8565.
2020-09-19deps: Update to github.com/tdewolff/minify v2.9.4Bjørn Erik Pedersen
2020-03-20Some minify configuration adjustmentsBjørn Erik Pedersen
2020-03-20Add minify configSatowTakeshi
Fixes #6750 Updates #6892
2020-01-23Revert to minify v2.6.1Bjørn Erik Pedersen
Closes #6791
2020-01-07minifiers: Update to new CSS configBjørn Erik Pedersen
Update #6719
2019-11-03minifiers: Add a JSON roundtrip testBjørn Erik Pedersen
See #6472
2019-08-12tests: Convert from testify to quicktestBjørn Erik Pedersen
2019-03-24all: Apply staticcheck recommendationsBjørn Erik Pedersen
2018-12-07minifiers: Fixx CSS2 color code handlingBjørn Erik Pedersen
Fixes #5506
2018-11-07deps: Update minifyBjørn Erik Pedersen
No functional changes, just support for Go Modules.
2018-09-13minifiers: Set minifier to KeepEndTagsAlexandros
See: https://github.com/tdewolff/minify/blob/948b6490cf3cacab5f4d7474104c3d21bf6eda46/README.md#L171
2018-09-12minifiers: Make JSON minification more genericJames Kiefer
Add a regex matcher for json types. Specifically support LD+JSON which allows for google seo minification out of the box. Expanded JS/JSON minification testing.
2018-08-28Improve minifier MIME type resolutionBjørn Erik Pedersen
This commit also removes the deprecated `Suffix` from MediaType. Now use `Suffixes` and put the MIME type suffix in the type, e.g. `application/svg+xml`. Fixes #5093
2018-08-25minfiers: Keep end tagsvsopvsop
Fixes #5112
2018-08-18minifiers: Do not strip IE conditional statementsBjørn Erik Pedersen
Fixes #5089
2018-08-14minifiers: Make the JS minifier matcher less specificBjørn Erik Pedersen
Fixes #5073
2018-08-06Add support for minification of final outputBjørn Erik Pedersen
Hugo Pipes added minification support for resources fetched via ´resources.Get` and similar. This also adds support for minification of the final output for supported output formats: HTML, XML, SVG, CSS, JavaScript, JSON. To enable, run Hugo with the `--minify` flag: ```bash hugo --minify ``` This commit is also a major spring cleaning of the `transform` package to allow the new minification step fit into that processing chain. Fixes #1251