mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-31 23:16:54 +00:00
document 非空判断
This commit is contained in:
@@ -22,7 +22,7 @@ const Slug = props => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (window) {
|
if (window) {
|
||||||
const article = document.getElementById('container')
|
const article = typeof document !== 'undefined' && document.getElementById('container')
|
||||||
if (!article) {
|
if (!article) {
|
||||||
router.push('/404').then(() => {
|
router.push('/404').then(() => {
|
||||||
console.warn('找不到页面', router.asPath)
|
console.warn('找不到页面', router.asPath)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const LayoutSearch = props => {
|
|||||||
const { keyword, posts } = props
|
const { keyword, posts } = props
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const container = document.getElementById('container')
|
const container = typeof document !== 'undefined' && document.getElementById('container')
|
||||||
if (container && container.innerHTML) {
|
if (container && container.innerHTML) {
|
||||||
const re = new RegExp(`${keyword}`, 'gim')
|
const re = new RegExp(`${keyword}`, 'gim')
|
||||||
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
|
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const LayoutSearch = (props) => {
|
|||||||
const currentSearch = keyword || router?.query?.s
|
const currentSearch = keyword || router?.query?.s
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const container = document.getElementById('container')
|
const container = typeof document !== 'undefined' && document.getElementById('container')
|
||||||
if (container && container.innerHTML) {
|
if (container && container.innerHTML) {
|
||||||
const re = new RegExp(`${currentSearch}`, 'gim')
|
const re = new RegExp(`${currentSearch}`, 'gim')
|
||||||
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${currentSearch}</span>`)
|
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${currentSearch}</span>`)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const Layout404 = props => {
|
|||||||
// 延时3秒如果加载失败就返回首页
|
// 延时3秒如果加载失败就返回首页
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (window) {
|
if (window) {
|
||||||
const article = document.getElementById('container')
|
const article = typeof document !== 'undefined' && document.getElementById('container')
|
||||||
if (!article) {
|
if (!article) {
|
||||||
router.push('/').then(() => {
|
router.push('/').then(() => {
|
||||||
console.log('找不到页面', router.asPath)
|
console.log('找不到页面', router.asPath)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const Progress = ({ targetRef, showPercent = true }) => {
|
|||||||
const currentRef = targetRef?.current || targetRef
|
const currentRef = targetRef?.current || targetRef
|
||||||
const [percent, changePercent] = useState(0)
|
const [percent, changePercent] = useState(0)
|
||||||
const scrollListener = () => {
|
const scrollListener = () => {
|
||||||
const target = currentRef || document.getElementById('container')
|
const target = currentRef || (typeof document !== 'undefined' && document.getElementById('container'))
|
||||||
if (target) {
|
if (target) {
|
||||||
const clientHeight = target.clientHeight
|
const clientHeight = target.clientHeight
|
||||||
const scrollY = window.pageYOffset
|
const scrollY = window.pageYOffset
|
||||||
|
|||||||
@@ -11,23 +11,23 @@ export const LayoutSearch = (props) => {
|
|||||||
const { keyword } = props
|
const { keyword } = props
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const container = document.getElementById('container')
|
const container = typeof document !== 'undefined' && document.getElementById('container')
|
||||||
if (container && container.innerHTML) {
|
if (container && container.innerHTML) {
|
||||||
const re = new RegExp(`${keyword}`, 'gim')
|
const re = new RegExp(`${keyword}`, 'gim')
|
||||||
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
|
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
100)
|
100)
|
||||||
})
|
})
|
||||||
return <LayoutBase {...props}>
|
return <LayoutBase {...props}>
|
||||||
<div className='py-12'>
|
<div className='py-12'>
|
||||||
<div className='pb-4 w-full'>{locale.NAV.SEARCH}</div>
|
<div className='pb-4 w-full'>{locale.NAV.SEARCH}</div>
|
||||||
<SearchInput currentSearch={keyword} {...props}/>
|
<SearchInput currentSearch={keyword} {...props} />
|
||||||
<TagGroups {...props}/>
|
<TagGroups {...props} />
|
||||||
<CategoryGroup {...props}/>
|
<CategoryGroup {...props} />
|
||||||
</div>
|
</div>
|
||||||
<div id='container'>
|
<div id='container'>
|
||||||
<BlogPostListScroll {...props}/>
|
<BlogPostListScroll {...props} />
|
||||||
</div>
|
</div>
|
||||||
</LayoutBase>
|
</LayoutBase>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const Progress = ({ targetRef, showPercent = true }) => {
|
|||||||
const currentRef = targetRef?.current || targetRef
|
const currentRef = targetRef?.current || targetRef
|
||||||
const [percent, changePercent] = useState(0)
|
const [percent, changePercent] = useState(0)
|
||||||
const scrollListener = () => {
|
const scrollListener = () => {
|
||||||
const target = currentRef || document.getElementById('container')
|
const target = currentRef || (typeof document !== 'undefined' && document.getElementById('container'))
|
||||||
if (target) {
|
if (target) {
|
||||||
const clientHeight = target.clientHeight
|
const clientHeight = target.clientHeight
|
||||||
const scrollY = window.pageYOffset
|
const scrollY = window.pageYOffset
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const Layout404 = props => {
|
|||||||
// 延时3秒如果加载失败就返回首页
|
// 延时3秒如果加载失败就返回首页
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (window) {
|
if (window) {
|
||||||
const article = document.getElementById('container')
|
const article = typeof document !== 'undefined' && document.getElementById('container')
|
||||||
if (!article) {
|
if (!article) {
|
||||||
router.push('/').then(() => {
|
router.push('/').then(() => {
|
||||||
console.log('找不到页面', router.asPath)
|
console.log('找不到页面', router.asPath)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const LayoutSearch = (props) => {
|
|||||||
const { locale } = useGlobal()
|
const { locale } = useGlobal()
|
||||||
const { posts, keyword } = props
|
const { posts, keyword } = props
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const container = document.getElementById('container')
|
const container = typeof document !== 'undefined' && document.getElementById('container')
|
||||||
if (container && container.innerHTML) {
|
if (container && container.innerHTML) {
|
||||||
const re = new RegExp(`${keyword}`, 'gim')
|
const re = new RegExp(`${keyword}`, 'gim')
|
||||||
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
|
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const Progress = ({ targetRef, showPercent = true }) => {
|
|||||||
const currentRef = targetRef?.current || targetRef
|
const currentRef = targetRef?.current || targetRef
|
||||||
const [percent, changePercent] = useState(0)
|
const [percent, changePercent] = useState(0)
|
||||||
const scrollListener = () => {
|
const scrollListener = () => {
|
||||||
const target = currentRef || document.getElementById('container')
|
const target = currentRef || (typeof document !== 'undefined' && document.getElementById('container'))
|
||||||
if (target) {
|
if (target) {
|
||||||
const clientHeight = target.clientHeight
|
const clientHeight = target.clientHeight
|
||||||
const scrollY = window.pageYOffset
|
const scrollY = window.pageYOffset
|
||||||
|
|||||||
Reference in New Issue
Block a user