Merge pull request #446 from tangly1024/main

发布tangly1024.com
This commit is contained in:
tangly1024
2022-11-13 19:17:37 +08:00
committed by GitHub
2 changed files with 12 additions and 14 deletions

View File

@@ -41,6 +41,7 @@ import 'prismjs/components/prism-swift.js'
import 'prismjs/components/prism-wasm.js'
import 'prismjs/components/prism-yaml.js'
import 'prismjs/components/prism-r.js'
import mermaid from 'mermaid'
const Collection = dynamic(() =>
import('react-notion-x/build/third-party/collection').then((m) => m.Collection), { ssr: true }
@@ -65,10 +66,18 @@ const NotionPage = ({ post }) => {
const zoomRef = React.useRef(zoom ? zoom.clone() : null)
React.useEffect(() => {
// 支持 Mermaid
const mermaids = document.querySelectorAll('.notion-code .language-mermaid')
for (const e of mermaids) {
const chart = e.innerText
e.parentElement.parentElement.innerHTML = `<div class="mermaid">${chart}</div>`
mermaid.contentLoaded()
}
setTimeout(() => {
if (window.location.hash) {
const tocNode = document.getElementById(window.location.hash.substring(1))
if (tocNode && tocNode.className.indexOf('notion') > -1) {
if (tocNode && tocNode?.className?.indexOf('notion') > -1) {
tocNode.scrollIntoView({ block: 'start', behavior: 'smooth' })
}
}
@@ -83,18 +92,6 @@ const NotionPage = ({ post }) => {
(zoomRef.current).attach(imgList[i])
}
}
// 相册中的url替换成可点击
const cards = document.getElementsByClassName('notion-collection-card')
for (const e of cards) {
e.removeAttribute('href')
const links = e.querySelectorAll('.notion-link')
if (links && links.length > 0) {
for (const l of links) {
l.parentElement.innerHTML = `<a href='${l.innerText}' rel='noreferrer' target='_blank'>${l.innerText}</a>`
}
}
}
}
}, 800)
@@ -139,7 +136,7 @@ function addWatch4Dom(element) {
case 'childList':
if (mutation.target.className === 'notion-code-copy') {
fixCopy(mutation.target)
} else if (mutation.target.className?.indexOf('language-') > -1) {
} else if (mutation.target.className && typeof (mutation.target.className) === 'string' && mutation?.target?.className?.indexOf('language-') > -1) {
const copyCode = mutation.target.parentElement?.firstElementChild
if (copyCode) {
fixCopy(copyCode)

View File

@@ -33,6 +33,7 @@
"lodash.throttle": "^4.1.1",
"memory-cache": "^0.2.0",
"mongodb": "^4.6.0",
"mermaid": "9.2.2",
"next": "12.1.6",
"notion-client": "6.15.6",
"notion-utils": "6.15.6",