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 {