feat(初步实现spoiler插件):

This commit is contained in:
anime
2024-12-30 16:11:32 +08:00
parent 9b80c149bf
commit 5ace2d1e40
4 changed files with 107 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
import { siteConfig } from '@/lib/config'
import { compressImage, mapImgUrl } from '@/lib/notion/mapImage'
import { isBrowser } from '@/lib/utils'
import { isBrowser, loadExternalResource } from '@/lib/utils'
import mediumZoom from '@fisch0920/medium-zoom'
import 'katex/dist/katex.min.css'
import dynamic from 'next/dynamic'
@@ -17,6 +17,7 @@ const NotionPage = ({ post, className }) => {
// 是否关闭数据库和画册的点击跳转
const POST_DISABLE_GALLERY_CLICK = siteConfig('POST_DISABLE_GALLERY_CLICK')
const POST_DISABLE_DATABASE_CLICK = siteConfig('POST_DISABLE_DATABASE_CLICK')
const SPOILER_TEXT_TAG = siteConfig('SPOILER_TEXT_TAG')
const zoom =
isBrowser &&
@@ -84,6 +85,20 @@ const NotionPage = ({ post, className }) => {
}
}, [post])
useEffect(() => {
if (SPOILER_TEXT_TAG) {
import('lodash/escapeRegExp').then(escapeRegExp => {
Promise.all([
loadExternalResource('/js/spoilerText.js', 'js'),
loadExternalResource('/css/spoiler-text.css', 'css')
]).then(() => {
window.textToSpoiler &&
window.textToSpoiler(escapeRegExp.default(SPOILER_TEXT_TAG))
})
})
}
}, [post])
return (
<div
id='notion-article'