Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/3.6.6 #602

Merged
merged 3 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 23 additions & 17 deletions components/PrismMac.js
Expand Up @@ -8,7 +8,6 @@ import 'prismjs/plugins/line-numbers/prism-line-numbers.css'
// 所有语言的prismjs 使用autoloader引入
import 'prismjs/plugins/autoloader/prism-autoloader'
// mermaid图
import mermaid from 'mermaid'
import BLOG from '@/blog.config'

/**
Expand All @@ -18,6 +17,7 @@ import BLOG from '@/blog.config'
const PrismMac = () => {
React.useEffect(() => {
renderPrismMac()
renderMermaid()

// 折叠代码行号bug
const observer = new MutationObserver(mutationsList => {
Expand All @@ -35,21 +35,10 @@ const PrismMac = () => {
return <></>
}

function renderPrismMac() {
const container = document?.getElementById('container-inner')
const codeToolBars = container?.getElementsByClassName('code-toolbar')

// 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'
}
})
}

/**
* 将mermaid语言 渲染成图片
*/
const renderMermaid = async() => {
// 支持 Mermaid
const mermaidPres = document.querySelectorAll('pre.notion-code.language-mermaid')
if (mermaidPres) {
Expand All @@ -73,9 +62,26 @@ function renderPrismMac() {
}
}
if (needLoad) {
mermaid.contentLoaded()
const asyncMermaid = await import('mermaid')
asyncMermaid.default.contentLoaded()
}
}
}

function renderPrismMac() {
const container = document?.getElementById('container-inner')
const codeToolBars = container?.getElementsByClassName('code-toolbar')

// 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'
}
})
}

// 重新渲染之前检查所有的多余text

Expand Down
5 changes: 0 additions & 5 deletions lib/busuanzi.js
Expand Up @@ -94,11 +94,6 @@ bszTag = {
}
}

// 修复Node同构代码的问题
if (typeof document !== 'undefined') {
fetch()
}

module.exports = {
fetch
}
9 changes: 5 additions & 4 deletions themes/next/components/Toc.js
Expand Up @@ -11,10 +11,6 @@ import Progress from './Progress'
* @constructor
*/
const Toc = ({ toc }) => {
// 无目录就直接返回空
if (!toc || toc.length < 1) {
return <></>
}
// 监听滚动事件
React.useEffect(() => {
window.addEventListener('scroll', actionSectionScrollSpy)
Expand Down Expand Up @@ -58,6 +54,11 @@ const Toc = ({ toc }) => {
tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' })
}, throttleMs))

// 无目录就直接返回空
if (!toc || toc.length < 1) {
return <></>
}

return <div className='px-3'>
<div className='w-full pb-1'>
<Progress />
Expand Down