Skip to content

Commit

Permalink
fix: preserve data-open css selectors
Browse files Browse the repository at this point in the history
`PurgeCSS` was removing styles using the `data-open` attribute. This
commit adds that attribute to a list of dynamic attributes to be
preserved.

resolves #18
  • Loading branch information
cjshearer committed Oct 29, 2023
1 parent ef9666d commit 66729ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions layouts/partials/css.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{ $styles := resources.Get "css/main.css" }}
{{ $styles := $styles | postCSS }}
{{ $styles := resources.Get "css/main.css" | resources.PostCSS }}
{{ if hugo.IsProduction }}
{{- with $styles | minify | fingerprint | resources.PostProcess -}}
<style>{{- .Content | safeCSS }}</style>
Expand Down
6 changes: 5 additions & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ if (process.env.HUGO_ENVIRONMENT === "production") {
/** @type {import('@fullhuman/postcss-purgecss').UserDefinedOptions} */
"@fullhuman/postcss-purgecss": {
content: ["./hugo_stats.json"],
defaultExtractor: (content) => JSON.parse(content).htmlElements,
dynamicAttributes: ["data-open"],
defaultExtractor: (content) => {
const els = JSON.parse(content).htmlElements;
return Object.values(els).reduce((acc, val) => acc.concat(val), []);
},
variables: true,
},
});
Expand Down

0 comments on commit 66729ab

Please sign in to comment.