diff --git a/components/PrismMac.js b/components/PrismMac.js index 2ec44618..1aab0ddc 100644 --- a/components/PrismMac.js +++ b/components/PrismMac.js @@ -55,33 +55,18 @@ function renderPrismMac() { }) } - setTimeout(() => { - // Add pre-mac element for Mac Style UI - if (codeToolBars) { - Array.from(codeToolBars).forEach(item => { - const existPreMac = item.getElementsByClassName('pre-mac') - if (existPreMac.length < codeToolBars.length) { - const preMac = document.createElement('div') - preMac.classList.add('pre-mac') - preMac.innerHTML = '' - item?.appendChild(preMac, item) - } - }) - } - }, 10) - // 支持 Mermaid const mermaids = document.querySelectorAll('.notion-code .language-mermaid') if (mermaids) { for (const e of mermaids) { - e.parentElement.parentElement.classList.remove('code-toolbar') + e.parentElement.classList.remove('code-toolbar') const chart = e.firstChild.textContent if (e.firstElementChild) { - e.parentElement.parentElement.remove() + e.parentElement.remove() continue } if (chart) { - e.parentElement.parentElement.innerHTML = `
${chart}
` + e.parentElement.innerHTML = `
${chart}
` } } } @@ -102,6 +87,19 @@ function renderPrismMac() { } catch (err) { console.log('代码渲染', err) } + + // Add pre-mac element for Mac Style UI + if (codeToolBars) { + Array.from(codeToolBars).forEach(item => { + const existPreMac = item.getElementsByClassName('pre-mac') + if (existPreMac.length < codeToolBars.length) { + const preMac = document.createElement('div') + preMac.classList.add('pre-mac') + preMac.innerHTML = '' + item?.appendChild(preMac, item) + } + }) + } } export default PrismMac diff --git a/pages/[...slug].js b/pages/[...slug].js index 64f3f113..63eb5e51 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -21,7 +21,7 @@ const Slug = props => { const router = Router.useRouter() // 文章锁🔐 - const [lock, setLock] = React.useState(true) + const [lock, setLock] = React.useState(post?.password && post?.password !== '') React.useEffect(() => { if (post?.password && post?.password !== '') { diff --git a/styles/prism-mac-style.css b/styles/prism-mac-style.css index 8efcf150..9f2c5098 100644 --- a/styles/prism-mac-style.css +++ b/styles/prism-mac-style.css @@ -67,4 +67,9 @@ pre[class*='language-'] { .notion-code-copy{ display: none; +} + +pre[class*="language-mermaid"] { + background: transparent !important; + @apply dark:bg-gray-200 !important; } \ No newline at end of file