summaryrefslogtreecommitdiffstats
path: root/publisher/htmlElementsCollector.go
AgeCommit message (Collapse)Author
2024-01-28all: Run gofumpt -l -w .Bjørn Erik Pedersen
2023-07-19publisher: Improve class collector for dynamic classesBjørn Erik Pedersen
E.g. * AlpinesJS' :class="isTrue 'class1' : 'class2'" * And dynamic classes with colon in them, e.g. `hover:bg-white`
2023-07-03Fix buildStats when tags and classes are disabledBjørn Erik Pedersen
Fixes #11202
2023-07-02Rework the build.writeStats structBjørn Erik Pedersen
Mostly to make it easier to toggle on/off this feature from the env. See #11191
2023-07-01Make build.writeStats a structBjørn Erik Pedersen
So you can do ```toml [build.writeStats] tags = true classes = true ids = false ``` Fixes #11191
2023-02-07Make the HTML collector parsing more robustBjørn Erik Pedersen
Most notably better handling self-closing elements Closes #10698
2023-02-05Fix slow HTML elements collector for the pre caseBjørn Erik Pedersen
``` name old time/op new time/op delta ElementsCollectorWriterPre-10 25.2µs ± 1% 3.4µs ± 0% -86.54% (p=0.029 n=4+4) name old alloc/op new alloc/op delta ElementsCollectorWriterPre-10 624B ± 0% 142B ± 0% -77.18% (p=0.029 n=4+4) name old allocs/op new allocs/op delta ElementsCollectorWriterPre-10 16.0 ± 0% 6.0 ± 0% -62.50% (p=0.029 n=4+4) ``` Fixes #10698
2021-05-19publisher: Make the HTML element collector more robustBjørn Erik Pedersen
Fixes #8530
2021-05-19Revert "publisher: Make the HTML element collector more robust"Bjørn Erik Pedersen
This reverts commit ef0f1a726901d6c614040cfc2d7e8f9a2ca97816.
2021-05-19Revert "publisher: Get the collector in line with the io.Writer interface"Bjørn Erik Pedersen
This reverts commit a9bcd38181ceb79afba82adcd4de1aebf571e74c.
2021-05-17publisher: Get the collector in line with the io.Writer interfaceBjørn Erik Pedersen
As in: Do not retain the input slice.
2021-05-17publisher: Make the HTML element collector more robustBjørn Erik Pedersen
Fixes #8530
2021-04-20publisher: Remove some unreachable codeBjørn Erik Pedersen
2021-04-20publisher: Some performance tweaks for the HTML elements collectorBjørn Erik Pedersen
2021-04-20publisher: Exclude comment and doctype elements from writeStatsDirk Olbrich
- Reorder code blocks - Rename cssClassCollectorWriter to htmlElementCollectorWriter, as it just collect html element information - Expand benchmark to test for minified and unminified content Fixes #8396 Fixes #8417
2021-04-07publisher: Skip script, pre and textarea content when looking for HTML elementsBjørn Erik Pedersen
Updates #7567
2021-02-01Trim whitespace in elements written to hugo_stats.jsonPavlo Matiash
Fixes #7958
2020-12-16all: Fix minor typosPhil Davis
2020-12-03all: Format code with gofumptBjørn Erik Pedersen
See https://github.com/mvdan/gofumpt
2020-11-27publisher: Fix memory usage in writeStatsBjørn Erik Pedersen
``` 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-09-28publisher: Fix writeStats with quote inside quotesBjørn Erik Pedersen
Fixes #7746
2020-07-23publisher: Collect transition attributes as classesBjørn Erik Pedersen
Fixes #7509
2020-05-27publisher: Fix tag collector for nested table elementsBjørn Erik Pedersen
Fixes #7318
2020-04-27Fix some missing JS class collector casesBjørn Erik Pedersen
Fixes #7216
2020-04-21Fix class collector when running with --minifyBjørn Erik Pedersen
Also add a related stresstest. Fixes #7161
2020-04-09Collect HTML elements during the build to use in PurgeCSS etc.Bjørn Erik Pedersen
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