Skip to content

Commit

Permalink
Merge pull request #1607 from tangly1024/feat/collapse-code-expand
Browse files Browse the repository at this point in the history
折叠代码块默认展开状态
  • Loading branch information
tangly1024 committed Nov 1, 2023
2 parents 2f5aa8c + 47cfa40 commit 23cbc03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ const BLOG = {

CODE_MAC_BAR: process.env.NEXT_PUBLIC_CODE_MAC_BAR || true, // 代码左上角显示mac的红黄绿图标
CODE_LINE_NUMBERS: process.env.NEXT_PUBLIC_CODE_LINE_NUMBERS || false, // 是否显示行号
CODE_COLLAPSE: process.env.NEXT_PUBLIC_CODE_COLLAPSE || true, // 是否折叠代码框
CODE_COLLAPSE: process.env.NEXT_PUBLIC_CODE_COLLAPSE || true, // 是否支持折叠代码框
CODE_COLLAPSE_EXPAND_DEFAULT: process.env.NEXT_PUBLIC_CODE_COLLAPSE_EXPAND_DEFAULT || true, // 折叠代码默认是展开状态

// END********代码相关********

// Mermaid 图表CDN
Expand Down
11 changes: 9 additions & 2 deletions components/PrismMac.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,20 @@ const renderCollapseCode = () => {
codeBlock.parentNode.insertBefore(collapseWrapper, codeBlock)
panel.appendChild(codeBlock)

header.addEventListener('click', () => {
function collapseCode() {
panel.classList.toggle('invisible')
panel.classList.toggle('h-0')
panel.classList.toggle('h-auto')
header.querySelector('svg').classList.toggle('rotate-180')
panelWrapper.classList.toggle('border-gray-300')
})
}

// 点击后折叠展开代码
header.addEventListener('click', collapseCode)
// 是否自动展开
if (JSON.parse(BLOG.CODE_COLLAPSE_EXPAND_DEFAULT)) {
header.click()
}
}
}

Expand Down

0 comments on commit 23cbc03

Please sign in to comment.