From 190bc50d9a8c6d5ac7fd38ee6e1b3be0ce48f5e0 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 23 Jun 2023 19:55:01 +0800 Subject: [PATCH] gitbook --- themes/gitbook/LayoutBase.js | 44 +++++++------ themes/gitbook/LayoutIndex.js | 8 +-- themes/gitbook/LayoutSlug.js | 19 +++--- themes/gitbook/components/Announcement.js | 21 +++++++ themes/gitbook/components/ArticleInfo.js | 9 +++ themes/gitbook/components/BlogPostCard.js | 61 ++----------------- .../gitbook/components/BlogPostListScroll.js | 15 +---- themes/gitbook/components/Footer.js | 2 +- themes/medium/LayoutBase.js | 4 +- themes/medium/components/Announcement.js | 21 +++++++ 10 files changed, 94 insertions(+), 110 deletions(-) create mode 100755 themes/gitbook/components/Announcement.js create mode 100644 themes/gitbook/components/ArticleInfo.js create mode 100755 themes/medium/components/Announcement.js diff --git a/themes/gitbook/LayoutBase.js b/themes/gitbook/LayoutBase.js index 970a3e55..8ceb9442 100644 --- a/themes/gitbook/LayoutBase.js +++ b/themes/gitbook/LayoutBase.js @@ -12,6 +12,8 @@ import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' import Live2D from '@/components/Live2D' import BLOG from '@/blog.config' +import BlogPostListScroll from './components/BlogPostListScroll' +import ArticleInfo from './components/ArticleInfo' const ThemeGlobalMedium = createContext() /** @@ -21,7 +23,7 @@ const ThemeGlobalMedium = createContext() * @constructor */ const LayoutBase = props => { - const { children, meta, showInfoCard = true, slotLeft, slotTop, siteInfo } = props + const { children, meta, posts, post, showInfoCard = true, slotLeft, slotRight, slotTop, siteInfo } = props const { locale } = useGlobal() const router = useRouter() const [tocVisible, changeTocVisible] = useState(false) @@ -45,22 +47,20 @@ const LayoutBase = props => { {/* 左侧推拉抽屉 */}
-
- - {slotLeft} -
- {router.pathname !== '/search' && } - {showInfoCard && } - {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && } -
-
- +
+ {slotLeft} + + {router.pathname !== '/search' && } + + {/* 所有文章列表 */} + +
-
+
-
+
{slotTop} {onLoading ? LoadingCover : children} @@ -80,17 +80,15 @@ const LayoutBase = props => {
- {/* 左侧推拉抽屉 */} -
+ {/* 右侧侧推拉抽屉 */} +
- - {slotLeft} -
- {router.pathname !== '/search' && } - {showInfoCard && } - {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && } -
-
+ {slotRight} + +
+ + {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && } +
diff --git a/themes/gitbook/LayoutIndex.js b/themes/gitbook/LayoutIndex.js index 41410467..6071f9fc 100644 --- a/themes/gitbook/LayoutIndex.js +++ b/themes/gitbook/LayoutIndex.js @@ -1,11 +1,11 @@ -import BLOG from '@/blog.config' -import BlogPostListPage from './components/BlogPostListPage' -import BlogPostListScroll from './components/BlogPostListScroll' import LayoutBase from './LayoutBase' +import Announcement from './components/Announcement' +import ArticleInfo from './components/ArticleInfo' export const LayoutIndex = (props) => { return - {BLOG.POST_LIST_STYLE === 'page' ? : } + {/* gitbook主题首页只显示公告 */} + } diff --git a/themes/gitbook/LayoutSlug.js b/themes/gitbook/LayoutSlug.js index 68308ab7..78b0f5b2 100644 --- a/themes/gitbook/LayoutSlug.js +++ b/themes/gitbook/LayoutSlug.js @@ -15,7 +15,7 @@ import CategoryItem from './components/CategoryItem' import TagItemMini from './components/TagItemMini' import ShareBar from '@/components/ShareBar' -export const LayoutSlug = props => { +export const LayoutSlug = (props) => { const { post, prev, next, siteInfo, lock, validPassword } = props const { locale } = useGlobal() @@ -23,20 +23,15 @@ export const LayoutSlug = props => { post?.date?.start_date || post?.createdTime, locale.LOCALE ) + + const slotRight = post?.toc && post?.toc?.length > 3 && + console.log(slotRight, post, 'jhhh') + if (!post) { - return + return } - - const slotLeft = post?.toc && post?.toc?.length > 3 && ( -
- - {/* */} -
- ) - return ( - + {/* 文章锁 */} {lock && } diff --git a/themes/gitbook/components/Announcement.js b/themes/gitbook/components/Announcement.js new file mode 100755 index 00000000..62df1ec2 --- /dev/null +++ b/themes/gitbook/components/Announcement.js @@ -0,0 +1,21 @@ +// import { useGlobal } from '@/lib/global' +import dynamic from 'next/dynamic' + +const NotionPage = dynamic(() => import('@/components/NotionPage')) + +const Announcement = ({ notice, className }) => { +// const { locale } = useGlobal() + if (notice?.blockMap) { + return
+
+ {/*
{locale.COMMON.ANNOUNCEMENT}
*/} + {notice && (
+ +
)} +
+
+ } else { + return <> + } +} +export default Announcement diff --git a/themes/gitbook/components/ArticleInfo.js b/themes/gitbook/components/ArticleInfo.js new file mode 100644 index 00000000..b2d58efe --- /dev/null +++ b/themes/gitbook/components/ArticleInfo.js @@ -0,0 +1,9 @@ +export default function ArticleInfo({ post }) { + if (!post) { + return null + } + return
+ + Last update: { post.date?.start_date} +
+} diff --git a/themes/gitbook/components/BlogPostCard.js b/themes/gitbook/components/BlogPostCard.js index 998dd086..fd277508 100644 --- a/themes/gitbook/components/BlogPostCard.js +++ b/themes/gitbook/components/BlogPostCard.js @@ -1,80 +1,27 @@ import BLOG from '@/blog.config' -import NotionPage from '@/components/NotionPage' -import { useGlobal } from '@/lib/global' import Link from 'next/link' import React from 'react' -import CONFIG_MEDIUM from '../config_medium' -import CategoryItem from './CategoryItem' -import TagItemMini from './TagItemMini' -import TwikooCommentCount from '@/components/TwikooCommentCount' const BlogPostCard = ({ post, showSummary }) => { - const showPreview = CONFIG_MEDIUM.POST_LIST_PREVIEW && post.blockMap - const { locale } = useGlobal() return (
-
+
- {CONFIG_MEDIUM.POST_LIST_COVER &&
- {/* eslint-disable-next-line @next/next/no-img-element */} - -
} - {post.title} + {post.category} - {post.title}
-
-
{post.date?.start_date}
- {CONFIG_MEDIUM.POST_LIST_CATEGORY && } - {CONFIG_MEDIUM.POST_LIST_TAG && post?.tagItems?.map(tag => )} - -
- -
- - {(!showPreview || showSummary) && ( -

- {post.summary} -

- )} - - {showPreview && ( -
- -
-
- - - {locale.COMMON.ARTICLE_DETAIL} - - - -
-
-
- )}
) diff --git a/themes/gitbook/components/BlogPostListScroll.js b/themes/gitbook/components/BlogPostListScroll.js index 2c7eafbd..2212d51e 100644 --- a/themes/gitbook/components/BlogPostListScroll.js +++ b/themes/gitbook/components/BlogPostListScroll.js @@ -1,7 +1,6 @@ import BLOG from '@/blog.config' import BlogPostCard from './BlogPostCard' import BlogPostListEmpty from './BlogPostListEmpty' -import { useGlobal } from '@/lib/global' import throttle from 'lodash.throttle' import React, { useCallback, useEffect, useRef, useState } from 'react' import { useRouter } from 'next/router' @@ -17,7 +16,8 @@ const BlogPostListScroll = ({ posts = [], currentSearch }) => { const postsPerPage = BLOG.POSTS_PER_PAGE const [page, updatePage] = useState(1) let filteredPosts = Object.assign(posts) - const searchKey = getSearchKey() + const router = useRouter() + const searchKey = getSearchKey(router) if (searchKey) { filteredPosts = posts.filter(post => { const tagContent = post.tags ? post.tags.join(' ') : '' @@ -56,7 +56,6 @@ const BlogPostListScroll = ({ posts = [], currentSearch }) => { }) const targetRef = useRef(null) - const { locale } = useGlobal() if (!postsToShow || postsToShow.length === 0) { return @@ -70,13 +69,6 @@ const BlogPostListScroll = ({ posts = [], currentSearch }) => { ))}
-
-
{ - handleGetMore() - }} - className='w-full my-4 py-4 text-center cursor-pointer dark:text-gray-200' - > {hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}
-
} } @@ -95,8 +87,7 @@ const getPostByPage = function (page, totalPosts, postsPerPage) { ) } -function getSearchKey() { - const router = useRouter() +function getSearchKey(router) { if (router.query && router.query.s) { return router.query.s } diff --git a/themes/gitbook/components/Footer.js b/themes/gitbook/components/Footer.js index b9d4f49c..cde8885e 100644 --- a/themes/gitbook/components/Footer.js +++ b/themes/gitbook/components/Footer.js @@ -14,7 +14,7 @@ const Footer = ({ title }) => { return (
{`${copyrightDate}`} {BLOG.AUTHOR}.
diff --git a/themes/medium/LayoutBase.js b/themes/medium/LayoutBase.js index 25c8be11..a50a071b 100644 --- a/themes/medium/LayoutBase.js +++ b/themes/medium/LayoutBase.js @@ -12,6 +12,7 @@ import { useGlobal } from '@/lib/global' import { useRouter } from 'next/router' import Live2D from '@/components/Live2D' import BLOG from '@/blog.config' +import Announcement from './components/Announcement' const ThemeGlobalMedium = createContext() /** @@ -21,7 +22,7 @@ const ThemeGlobalMedium = createContext() * @constructor */ const LayoutBase = props => { - const { children, meta, showInfoCard = true, slotRight, slotTop, siteInfo } = props + const { children, meta, showInfoCard = true, slotRight, slotTop, siteInfo, notice } = props const { locale } = useGlobal() const router = useRouter() const [tocVisible, changeTocVisible] = useState(false) @@ -78,6 +79,7 @@ const LayoutBase = props => { {CONFIG_MEDIUM.WIDGET_REVOLVER_MAPS === 'true' && }
+
diff --git a/themes/medium/components/Announcement.js b/themes/medium/components/Announcement.js new file mode 100755 index 00000000..854aa388 --- /dev/null +++ b/themes/medium/components/Announcement.js @@ -0,0 +1,21 @@ +// import { useGlobal } from '@/lib/global' +import dynamic from 'next/dynamic' + +const NotionPage = dynamic(() => import('@/components/NotionPage')) + +const Announcement = ({ post, className }) => { +// const { locale } = useGlobal() + if (post?.blockMap) { + return
+
+ {/*
{locale.COMMON.ANNOUNCEMENT}
*/} + {post && (
+ +
)} +
+
+ } else { + return <> + } +} +export default Announcement