Commit graph

10 commits

Author SHA1 Message Date
Bjørn Erik Pedersen
3d5dbdcb1a publisher: Also test minified HTML in the element collector
Updates #7567
2021-04-07 16:40:15 +02:00
Bjørn Erik Pedersen
8a308944e4 publisher: Skip script, pre and textarea content when looking for HTML elements
Updates #7567
2021-04-07 00:26:02 +02:00
Bjørn Erik Pedersen
d90e37e0c6 all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
2020-12-03 13:12:58 +01:00
Bjørn Erik Pedersen
d162bbd799
publisher: Fix memory usage in writeStats
```
name                     old time/op    new time/op    delta
ClassCollectorWriter-16    72.1µs ± 0%    32.3µs ± 0%  -55.17%  (p=0.029 n=4+4)

name                     old alloc/op   new alloc/op   delta
ClassCollectorWriter-16    85.9kB ± 0%    35.1kB ± 0%  -59.16%  (p=0.029 n=4+4)

name                     old allocs/op  new allocs/op  delta
ClassCollectorWriter-16       329 ± 0%       149 ± 0%  -54.71%  (p=0.029 n=4+4)
```

Fixes #7945
2020-11-27 09:13:16 +01:00
Bjørn Erik Pedersen
111344113b
publisher: Fix writeStats with quote inside quotes
Fixes #7746
2020-09-28 22:17:36 +02:00
Bjørn Erik Pedersen
00e00da233 publisher: Collect transition attributes as classes
Fixes #7509
2020-07-23 16:21:58 +02:00
Bjørn Erik Pedersen
c950c86b4e publisher: Fix tag collector for nested table elements
Fixes #7318
2020-05-27 11:10:48 +02:00
Bjørn Erik Pedersen
c03ea2b660 Fix some missing JS class collector cases
Fixes #7216
2020-04-27 19:06:29 +02:00
Bjørn Erik Pedersen
f37e77f2d3 Fix class collector when running with --minify
Also add a related stresstest.

Fixes #7161
2020-04-21 21:00:52 +02:00
Bjørn Erik Pedersen
095bf64c99
Collect HTML elements during the build to use in PurgeCSS etc.
The main use case for this is to use with resources.PostProcess and resources.PostCSS with purgecss.

You would normally set it up to extract keywords from your templates, doing it from the full /public takes forever for bigger sites.

Doing the template thing misses dynamically created class names etc., and it's hard/impossible to set up in when using themes.

You can enable this in your site config:

```toml
[build]
  writeStats = true
```

It will then write a `hugo_stats.json` file to the project root as part of the build.

If you're only using this for the production build, you should consider putting it below `config/production`.

You can then set it up with PostCSS like this:

```js
const purgecss = require('@fullhuman/postcss-purgecss')({
    content: [ './hugo_stats.json' ],
    defaultExtractor: (content) => {
        let els = JSON.parse(content).htmlElements;
        return els.tags.concat(els.classes, els.ids);
    }
});

module.exports = {
    plugins: [
        require('tailwindcss'),
        require('autoprefixer'),
        ...(process.env.HUGO_ENVIRONMENT === 'production' ? [ purgecss ] : [])
    ]
};
```

Fixes #6999
2020-04-09 22:57:26 +02:00