diff --git a/components/ArticleDetail.js b/components/ArticleDetail.js
index 83dc82b0..b8c6ddd3 100644
--- a/components/ArticleDetail.js
+++ b/components/ArticleDetail.js
@@ -23,11 +23,7 @@ import { useGlobal } from '@/lib/global'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faEye, faFolderOpen } from '@fortawesome/free-solid-svg-icons'
import BlogAround from '@/components/BlogAround'
-import { useRef } from 'react'
-
-const mapPageUrl = id => {
- return 'https://www.notion.so/' + id.replace(/-/g, '')
-}
+import { useEffect, useRef } from 'react'
/**
*
@@ -40,85 +36,90 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n
const url = BLOG.link + useRouter().asPath
const { locale } = useGlobal()
const date = formatDate(post?.date?.start_date || post.createdTime, BLOG.lang)
- return (
- <>
-
-
-
-
{
+ countWords()
+ })
+
+ return (<>
+
+
- {post.type && !post.type.includes('Page') && post?.page_cover && (
- <>
-
- >
- )}
- {/* 文章Title */}
-
- {' '}
- {post.title}
-
-
-
-
-
-
- {post.category}
-
-
- {post.type[0] !== 'Page' && (
-
-
- {date}
-
-
- )}
+
+ {post.type && !post.type.includes('Page') && post?.page_cover && (
+
+
+
+ )}
+ {/* 文章Title */}
+
+ {' '}
+ {post.title}
+
+
+
+
+
+
+
+
+
-
+
+
+
+
{/* Notion文章主体 */}
- {blockMap && (
-
- )}
+
+ {blockMap && (
+
+ )}
+
{/* 推荐文章 */}
@@ -170,19 +171,57 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n
-
{/* 悬浮目录按钮 */}
- {
- drawerRight.current.handleSwitchVisible()
- }}
- />
- {/* 目录侧边栏 */}
+ { drawerRight.current.handleSwitchVisible() }} />
- >
- )
+
+
+ >)
+}
+
+const mapPageUrl = id => {
+ return 'https://www.notion.so/' + id.replace(/-/g, '')
+}
+
+/**
+ * 更新字数统计和阅读时间
+ */
+function countWords () {
+ if (window) {
+ const articleElement = document.getElementById('notion-article')
+ if (articleElement) {
+ const articleText = deleteHtmlTag(articleElement.innerHTML)
+ const wordCount = fnGetCpmisWords(articleText)
+ // 阅读速度 300-500每分钟
+ document.getElementById('wordCount').innerHTML = wordCount
+ document.getElementById('readTime').innerHTML = Math.floor(wordCount / 400)
+ }
+ }
+}
+
+// 去除html标签
+function deleteHtmlTag (str) {
+ str = str.replace(/<[^>]+>|&[^>]+;/g, '').trim()// 去掉所有的html标签和 之类的特殊符合
+ return str
+}
+
+// 用word方式计算正文字数
+function fnGetCpmisWords (str) {
+ let sLen = 0
+ try {
+ // eslint-disable-next-line no-irregular-whitespace
+ str = str.replace(/(\r\n+|\s+| +)/g, '龘')
+ // eslint-disable-next-line no-control-regex
+ str = str.replace(/[\x00-\xff]/g, 'm')
+ str = str.replace(/m+/g, '*')
+ str = str.replace(/龘+/g, '')
+ sLen = str.length
+ } catch (e) {
+
+ }
+ return sLen
}
diff --git a/components/BlogAround.js b/components/BlogAround.js
index 53231eb1..986b337f 100644
--- a/components/BlogAround.js
+++ b/components/BlogAround.js
@@ -11,7 +11,7 @@ export default function BlogAround ({ prev, next }) {
if (!prev || !next) {
return <>>
}
- return