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 1/4] 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 ecd784977..9d1da1878 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 = { From 548f096572c4ab663593b055b9fec40024737190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 6 Jan 2025 21:34:34 +0100 Subject: [PATCH 2/4] Add changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- changelogs/internal/newsfragments/2049.clarification | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/internal/newsfragments/2049.clarification diff --git a/changelogs/internal/newsfragments/2049.clarification b/changelogs/internal/newsfragments/2049.clarification new file mode 100644 index 000000000..935b0a04a --- /dev/null +++ b/changelogs/internal/newsfragments/2049.clarification @@ -0,0 +1 @@ +Fix click-to-copy buttons for code blocks. From 36599d4bb92dce3fac1c7536b6d24c981022691e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 6 Jan 2025 21:42:34 +0100 Subject: [PATCH 3/4] Fix JS script paths because they are minified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- postcss.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postcss.config.js b/postcss.config.js index 9d1da1878..50e7224ff 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -4,8 +4,8 @@ const purgecss = require('@fullhuman/postcss-purgecss')({ // 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', + process.env.HUGO_PUBLISHDIR + '/js/click-to-copy.min.*.js', + process.env.HUGO_PUBLISHDIR + '/js/main.min.*.js', ], extractors: [ { From 335e3fd0c3e8d514c71f660e2f6b58aa168e93d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 6 Jan 2025 21:47:45 +0100 Subject: [PATCH 4/4] Fix changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- changelogs/internal/newsfragments/2049.clarification | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/internal/newsfragments/2049.clarification b/changelogs/internal/newsfragments/2049.clarification index 935b0a04a..5a6e90f1b 100644 --- a/changelogs/internal/newsfragments/2049.clarification +++ b/changelogs/internal/newsfragments/2049.clarification @@ -1 +1 @@ -Fix click-to-copy buttons for code blocks. +Fix syntax highlighting and click-to-copy buttons for code blocks by purging less CSS.