Skip to content

Commit

Permalink
Fix click-to-copy buttons for code blocks
Browse files Browse the repository at this point in the history
It turns out that we were purging too much CSS which broke their style.

We use a simple but lazy solution that parses the JS scripts and keeps the matching selectors.

Signed-off-by: Kévin Commaille <[email protected]>
  • Loading branch information
zecakeh committed Jan 6, 2025
1 parent 6f1e64c commit 646087c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// Remove unused CSS selectors.
const purgecss = require('@fullhuman/postcss-purgecss')({
// Use stats generated by Hugo.
content: [ './hugo_stats.json' ],
defaultExtractor: (content) => {
let els = JSON.parse(content).htmlElements;
return els.tags.concat(els.classes, els.ids);
}
content: [
// Use stats generated by Hugo from HTML content.
'./hugo_stats.json',
// Add used JS scripts.
process.env.HUGO_PUBLISHDIR + '/js/click-to-copy.js',
process.env.HUGO_PUBLISHDIR + '/js/main.js',
],
extractors: [
{
extractor: (content) => {
let els = JSON.parse(content).htmlElements;
return els.tags.concat(els.classes, els.ids);
},
extensions: ["json"],
},
],
});

module.exports = {
Expand Down

0 comments on commit 646087c

Please sign in to comment.