From 646087cfb9a9a25e0ab37e661ee3d6f4015afcc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 6 Jan 2025 21:30:06 +0100 Subject: [PATCH] Fix click-to-copy buttons for code blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- postcss.config.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/postcss.config.js b/postcss.config.js index ecd78497..9d1da187 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -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 = {