diff --git a/components/ThemeSwitch.js b/components/ThemeSwitch.js index 2a8a76e7..af14904d 100644 --- a/components/ThemeSwitch.js +++ b/components/ThemeSwitch.js @@ -13,7 +13,8 @@ export function ThemeSwitch() {
-
{theme}
+
{theme} +
diff --git a/themes/matery/LayoutBase.js b/themes/matery/LayoutBase.js index 14352875..18387469 100644 --- a/themes/matery/LayoutBase.js +++ b/themes/matery/LayoutBase.js @@ -11,6 +11,7 @@ import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' import AOS from 'aos' import 'aos/dist/aos.css' // You can also use for styles +import FloatDarkModeButton from './components/FloatDarkModeButton' /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 @@ -46,39 +47,41 @@ const LayoutBase = props => { AOS.init() return ( -
+
- + - + - {headerSlot} + {headerSlot} -
-
- {onLoading ? : children} +
+
+ {onLoading ? : children} +
+
+ + {/* 左下角悬浮 */} +
+ +
+ +
+ +
+ {/* 右下角悬浮 */} +
+
+ +
+
+ +
-
- - {/* 左下角悬浮 */} -
- -
- - {/* 右下角悬浮 */} -
-
- -
-
- -
-
) } diff --git a/themes/matery/LayoutSearch.js b/themes/matery/LayoutSearch.js index 679975cb..bed5cefc 100644 --- a/themes/matery/LayoutSearch.js +++ b/themes/matery/LayoutSearch.js @@ -40,7 +40,7 @@ export const LayoutSearch = props => { return ( {!currentSearch && <> -
+
{/* 分类 */} diff --git a/themes/matery/LayoutSlug.js b/themes/matery/LayoutSlug.js index 0e0f1cb3..71122962 100644 --- a/themes/matery/LayoutSlug.js +++ b/themes/matery/LayoutSlug.js @@ -10,6 +10,7 @@ import NotionPage from '@/components/NotionPage' import ArticleAdjacent from './components/ArticleAdjacent' import ArticleCopyright from './components/ArticleCopyright' import { isBrowser } from '@/lib/utils' +import { ArticleInfo } from './components/ArticleInfo' export const LayoutSlug = props => { const { post, lock, validPassword } = props @@ -17,79 +18,83 @@ export const LayoutSlug = props => { if (!post) { return } - {...props} - showCategory={false} - showTag={false} - > + headerSlot={} + {...props} + showCategory={false} + showTag={false} + > } const targetRef = isBrowser() ? document.getElementById('container') : null const floatSlot = <> - {post?.toc?.length > 1 &&
- { - drawerRight?.current?.handleSwitchVisible() - }} - /> -
} - - + {post?.toc?.length > 1 &&
+ { + drawerRight?.current?.handleSwitchVisible() + }} + /> +
} + + return ( - } - {...props} - showCategory={false} - showTag={false} - floatSlot={floatSlot} - > -
-
- {lock && } + } + {...props} + showCategory={false} + showTag={false} + floatSlot={floatSlot} + > +
+
+ {lock && } - {!lock &&
+ {!lock &&
+ {/* + +
-
- {/* Notion文章主体 */} -
- {post && } -
+
-
- {/* 文章内嵌广告 */} - -
+
+ {/* Notion文章主体 */} +
+ {post && } +
- {post.type === 'Post' && } +
+ {/* 文章内嵌广告 */} + +
-
+ {post.type === 'Post' && } -
+
- {/* 评论互动 */} -
- -
-
} -
+
-
- {post.type === 'Post' && } -
+ {/* 评论互动 */} +
+ +
+
} +
-
-
- -
+ {post.type === 'Post' && } -
+
+
+ +
+ + ) } diff --git a/themes/matery/LayoutTag.js b/themes/matery/LayoutTag.js index 1eb2c249..5e26addd 100644 --- a/themes/matery/LayoutTag.js +++ b/themes/matery/LayoutTag.js @@ -3,24 +3,38 @@ import BlogPostListScroll from './components/BlogPostListScroll' import BlogPostListPage from './components/BlogPostListPage' import LayoutBase from './LayoutBase' import React from 'react' -import Link from 'next/link' +import HeaderArticle from './components/HeaderArticle' +import { useGlobal } from '@/lib/global' +import TagItemMiddle from './components/TagItemMiddle' export const LayoutTag = (props) => { - const tag = props.tags.find((t) => { - return t.name === props.tag - }) + const { tags, tag } = props - return - {tag && ( -
- - -
#{tag.name + (tag.count ? `(${tag.count})` : '')}
-
- + const { locale } = useGlobal() + + return } > + +
+ +
+ +
+ {locale.COMMON.TAGS} +
+ +
+ {tags.map(e => { + const selected = tag === e.name + return ( +
+ +
+ ) + })} +
- )} +
+ {BLOG.POST_LIST_STYLE === 'page' ? : }
} diff --git a/themes/matery/LayoutTagIndex.js b/themes/matery/LayoutTagIndex.js index 7649a704..1a5c2cc0 100644 --- a/themes/matery/LayoutTagIndex.js +++ b/themes/matery/LayoutTagIndex.js @@ -1,28 +1,32 @@ import { useGlobal } from '@/lib/global' -import Card from './components/Card' -import TagItemMini from './components/TagItemMini' +import HeaderArticle from './components/HeaderArticle' +import TagItemMiddle from './components/TagItemMiddle' import LayoutBase from './LayoutBase' export const LayoutTagIndex = props => { const { tags } = props const { locale } = useGlobal() return ( - - -
- - {locale.COMMON.TAGS}: -
-
- {tags.map(tag => { - return ( -
- -
- ) - })} -
-
-
+ } > +
+ +
+ +
+ {locale.COMMON.TAGS} +
+ +
+ {tags.map(tag => { + return ( +
+ +
+ ) + })} +
+
+
+
) } diff --git a/themes/matery/components/ArticleAdjacent.js b/themes/matery/components/ArticleAdjacent.js index 9430ed2b..0a9e00c4 100644 --- a/themes/matery/components/ArticleAdjacent.js +++ b/themes/matery/components/ArticleAdjacent.js @@ -10,7 +10,7 @@ export default function ArticleAdjacent ({ prev, next }) { if (!prev || !next || !CONFIG_MATERY.ARTICLE_ADJACENT) { return <> } - return
+ return
diff --git a/themes/matery/components/ArticleInfo.js b/themes/matery/components/ArticleInfo.js new file mode 100644 index 00000000..f2c72b9c --- /dev/null +++ b/themes/matery/components/ArticleInfo.js @@ -0,0 +1,46 @@ +import Link from 'next/link' +import { useGlobal } from '@/lib/global' +import formatDate from '@/lib/formatDate' +import TagItemMiddle from './TagItemMiddle' +import WordCount from './WordCount' + +export const ArticleInfo = (props) => { + const { post } = props + + const { locale } = useGlobal() + const date = formatDate(post?.date?.start_date || post?.createdTime, locale.LOCALE) + + return
+
+ {post.tagItems && ( +
+ {post.tagItems.map(tag => ( + + ))} +
+ )} +
+ +
+ {post?.type !== 'Page' && (<> + + + 发布日期: {date} + + + + 更新日期: {post.lastEditedTime} + + + + + + + )} +
+ +
+} diff --git a/themes/matery/components/BlogPostCard.js b/themes/matery/components/BlogPostCard.js index 14e7ccbd..ba4e9c4b 100644 --- a/themes/matery/components/BlogPostCard.js +++ b/themes/matery/components/BlogPostCard.js @@ -6,6 +6,7 @@ import CONFIG_MATERY from '../config_matery' const BlogPostCard = ({ post, showSummary }) => { const showPreview = CONFIG_MATERY.POST_LIST_PREVIEW && post.blockMap + console.log('文章', post) return (
{
{/* 头部图片 填充卡片 */} - {CONFIG_MATERY.POST_LIST_COVER && !showPreview && post?.page_cover && !post.results && ( + {CONFIG_MATERY.POST_LIST_COVER && !showPreview && post?.page_cover && (
{/* eslint-disable-next-line @next/next/no-img-element */} @@ -31,7 +32,7 @@ const BlogPostCard = ({ post, showSummary }) => { alt={post.title} className="opacity-50 h-full w-full hover:scale-125 rounded-t-md transform object-cover duration-500" /> - {post.title} + {post.title}
)} @@ -46,6 +47,14 @@ const BlogPostCard = ({ post, showSummary }) => { {post.summary}

)} + {/* 搜索结果 */} + {post.results && ( +

+ {post.results.map(r => ( + {r} + ))} +

+ )}
{ return
<>{headerSlot} -
+
{children}
diff --git a/themes/matery/components/FloatDarkModeButton.js b/themes/matery/components/FloatDarkModeButton.js index 2c85932b..81d42875 100644 --- a/themes/matery/components/FloatDarkModeButton.js +++ b/themes/matery/components/FloatDarkModeButton.js @@ -2,12 +2,13 @@ import { useGlobal } from '@/lib/global' import { saveDarkModeToCookies } from '@/lib/theme' import CONFIG_MATERY from '../config_matery' -export default function FloatDarkModeButton () { +export default function FloatDarkModeButton() { + const { isDarkMode, updateDarkMode } = useGlobal() + if (!CONFIG_MATERY.WIDGET_DARK_MODE) { return <> } - const { isDarkMode, updateDarkMode } = useGlobal() // 用户手动设置主题 const handleChangeDarkMode = () => { const newStatus = !isDarkMode @@ -19,12 +20,13 @@ export default function FloatDarkModeButton () { } return ( -
- -
+
+ +
) } diff --git a/themes/matery/components/HeaderArticle.js b/themes/matery/components/HeaderArticle.js index 984dc314..b02376a2 100644 --- a/themes/matery/components/HeaderArticle.js +++ b/themes/matery/components/HeaderArticle.js @@ -1,8 +1,6 @@ export default function HeaderArticle({ post, siteInfo }) { - if (!post) { - return <> - } - const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("${siteInfo?.pageCover}")` + const headerImage = post?.page_cover ? `url("${post?.page_cover}")` : `url("${siteInfo?.pageCover}")` + const title = post?.title return ( diff --git a/themes/matery/components/SideBar.js b/themes/matery/components/SideBar.js index 41bd4eb5..722b35b6 100644 --- a/themes/matery/components/SideBar.js +++ b/themes/matery/components/SideBar.js @@ -30,7 +30,7 @@ const SideBar = (props) => {
{/* eslint-disable-next-line @next/next/no-img-element */} - {BLOG.AUTHOR} + {BLOG.AUTHOR}
{siteInfo?.title}
{siteInfo?.description}
diff --git a/themes/matery/components/TagItemMiddle.js b/themes/matery/components/TagItemMiddle.js new file mode 100644 index 00000000..7034a31e --- /dev/null +++ b/themes/matery/components/TagItemMiddle.js @@ -0,0 +1,14 @@ +import Link from 'next/link' + +const TagItemMiddle = ({ tag, selected = false }) => { + return + +
+ {selected && } + {tag.name + (tag.count ? `(${tag.count})` : '')}
+
+ +} + +export default TagItemMiddle diff --git a/themes/matery/components/WordCount.js b/themes/matery/components/WordCount.js new file mode 100644 index 00000000..783e37c9 --- /dev/null +++ b/themes/matery/components/WordCount.js @@ -0,0 +1,65 @@ +import { useEffect } from 'react' + +/** + * 字数统计 + * @returns + */ +export default function WordCount() { + useEffect(() => { + countWords() + }) + + return + + + 文章字数 + 0 + + + 阅读时长: + 0 分钟 + + +} + +/** + * 更新字数统计和阅读时间 + */ +function countWords() { + const articleText = deleteHtmlTag(document.getElementById('notion-article')?.innerHTML) + const wordCount = fnGetCpmisWords(articleText) + // 阅读速度 300-500每分钟 + document.getElementById('wordCount').innerHTML = wordCount + document.getElementById('readTime').innerHTML = Math.floor(wordCount / 400) + 1 + const wordCountWrapper = document.getElementById('wordCountWrapper') + wordCountWrapper.classList.remove('hidden') +} + +// 去除html标签 +function deleteHtmlTag(str) { + if (!str) { + return '' + } + str = str.replace(/<[^>]+>|&[^>]+;/g, '').trim()// 去掉所有的html标签和 之类的特殊符合 + return str +} + +// 用word方式计算正文字数 +function fnGetCpmisWords(str) { + if (!str) { + return 0 + } + 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 +}