fix(使所有主题的404能够正常运转): 同时让获取文章DOM节点也避免公告栏等其他位置的干扰

This commit is contained in:
anime
2024-11-08 00:30:44 +08:00
parent 3374068163
commit c8d90a4166
20 changed files with 25 additions and 25 deletions

View File

@@ -304,7 +304,7 @@ const Layout404 = props => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/').then(() => {
// console.log('找不到页面', router.asPath)

View File

@@ -162,7 +162,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -143,7 +143,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -255,7 +255,7 @@ const LayoutIndex = props => {
// 重定向到指定文章
router.push(index).then(() => {
setTimeout(() => {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
console.log(
'请检查您的Notion数据库中是否包含此slug页面 ',
@@ -309,7 +309,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -273,7 +273,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -269,7 +269,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
@@ -333,7 +333,7 @@ const Layout404 = props => {
// 延时3秒如果加载失败就返回首页
setTimeout(() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/').then(() => {
// console.log('找不到页面', router.asPath)

View File

@@ -82,7 +82,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -155,7 +155,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -29,7 +29,7 @@ export default function WordCount() {
* 更新字数统计和阅读时间
*/
function countWords() {
const articleText = deleteHtmlTag(document.getElementById('notion-article')?.innerHTML)
const articleText = deleteHtmlTag(document.querySelector('#article-wrapper #notion-article')?.innerHTML)
const wordCount = fnGetCpmisWords(articleText)
// 阅读速度 300-500每分钟
document.getElementById('wordCount').innerHTML = wordCount

View File

@@ -231,7 +231,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)
@@ -320,7 +320,7 @@ const Layout404 = props => {
setTimeout(() => {
const article =
typeof document !== 'undefined' &&
document.getElementById('notion-article')
document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/').then(() => {
// console.log('找不到页面', router.asPath)

View File

@@ -191,7 +191,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -156,7 +156,7 @@ const LayoutSlug = props => {
// 用js 实现将页面中的多个视频聚合为一个分集的视频
function combineVideo() {
// 找到 id 为 notion-article 的元素
const notionArticle = document.getElementById('notion-article')
const notionArticle = document.querySelector('#article-wrapper #notion-article')
if (!notionArticle) return // 如果找不到对应的元素,则退出函数
// 找到所有的 .notion-asset-wrapper 元素
@@ -291,7 +291,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -261,7 +261,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -23,7 +23,7 @@ export default function WordCount() {
* 更新字数统计和阅读时间
*/
function countWords() {
const articleText = deleteHtmlTag(document.getElementById('notion-article')?.innerHTML)
const articleText = deleteHtmlTag(document.querySelector('#article-wrapper #notion-article')?.innerHTML)
const wordCount = fnGetCpmisWords(articleText)
// 阅读速度 300-500每分钟
document.getElementById('wordCount').innerHTML = wordCount

View File

@@ -328,7 +328,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -227,7 +227,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -156,7 +156,7 @@ const LayoutSlug = props => {
// 用js 实现将页面中的多个视频聚合为一个分集的视频
function combineVideo() {
// 找到 id 为 notion-article 的元素
const notionArticle = document.getElementById('notion-article')
const notionArticle = document.querySelector('#article-wrapper #notion-article')
if (!notionArticle) return // 如果找不到对应的元素,则退出函数
// 找到所有的 .notion-asset-wrapper 元素
@@ -291,7 +291,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -182,7 +182,7 @@ const LayoutSlug = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)

View File

@@ -273,7 +273,7 @@ const Layout404 = props => {
setTimeout(
() => {
if (isBrowser) {
const article = document.getElementById('notion-article')
const article = document.querySelector('#article-wrapper #notion-article')
if (!article) {
router.push('/404').then(() => {
console.warn('找不到页面', router.asPath)