From 24989691066acf6b37131ac1aa4f07cb536696d4 Mon Sep 17 00:00:00 2001 From: expoli <31023767+expoli@users.noreply.github.com> Date: Wed, 18 Jan 2023 09:51:25 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=A1=8C=E5=8F=B7=E6=98=BE=E7=A4=BA=E6=8E=A7=E5=88=B6=EF=BC=8C?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=A1=8C=E5=8F=B7=E6=98=BE=E7=A4=BA=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=B0=86=E4=BB=A3=E7=A0=81=E8=BF=9B=E8=A1=8C=E5=B7=A6?= =?UTF-8?q?=E5=8F=B3=E6=BB=91=E5=8A=A8=EF=BC=8C=E9=BB=98=E8=AE=A4=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E8=A1=8C=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 1 + components/PrismMac.js | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/blog.config.js b/blog.config.js index 653d3fe3..2c48088d 100644 --- a/blog.config.js +++ b/blog.config.js @@ -43,6 +43,7 @@ const BLOG = { // PrismJs CDN PRISM_JS_PATH: 'https://npm.elemecdn.com/prismjs@1.29.0/components/', + CODE_LINE_NUMBERS: process.env.NEXT_PUBLIC_CODE_LINE_NUMBERS || 'false', BACKGROUND_LIGHT: '#eeeeee', // use hex value, don't forget '#' e.g #fffefc BACKGROUND_DARK: '#000000', // use hex value, don't forget '#' diff --git a/components/PrismMac.js b/components/PrismMac.js index 11673d46..41d5e588 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -73,16 +73,17 @@ function renderPrismMac() { const container = document?.getElementById('container-inner') // Add line numbers - const codeBlocks = container?.getElementsByTagName('pre') - if (codeBlocks) { - Array.from(codeBlocks).forEach(item => { - if (!item.classList.contains('line-numbers')) { - item.classList.add('line-numbers') - item.style.whiteSpace = 'pre-wrap' - } - }) + if (BLOG.CODE_LINE_NUMBERS === 'true') { + const codeBlocks = container?.getElementsByTagName('pre') + if (codeBlocks) { + Array.from(codeBlocks).forEach(item => { + if (!item.classList.contains('line-numbers')) { + item.classList.add('line-numbers') + item.style.whiteSpace = 'pre-wrap' + } + }) + } } - // 重新渲染之前检查所有的多余text try {