From f2e2ae8d5fc45781aaca020999e45af808eee2dc Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 7 Nov 2023 14:52:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6Notion=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config.js | 10 +- themes/example/components/BlogListPage.js | 2 +- themes/example/components/BlogListScroll.js | 2 +- themes/example/components/BlogPostCard.js | 2 +- themes/example/components/Nav.js | 8 +- themes/example/config.js | 10 +- themes/fukasawa/components/AsideLeft.js | 2 +- themes/fukasawa/components/BlogCard.js | 8 +- themes/fukasawa/components/MenuList.js | 10 +- themes/fukasawa/config.js | 18 ++-- themes/fukasawa/index.js | 4 +- themes/gitbook/components/MenuBarMobile.js | 8 +- themes/gitbook/components/NavPostList.js | 3 +- themes/gitbook/components/TopNavBar.js | 8 +- themes/gitbook/config.js | 16 ++-- themes/gitbook/index.js | 14 +-- themes/heo/components/AnalyticsCard.js | 3 +- themes/heo/components/ArticleAdjacent.js | 3 +- themes/heo/components/ArticleCopyright.js | 2 +- themes/heo/components/ArticleRecommend.js | 2 +- themes/heo/components/BlogPostArchive.js | 6 +- themes/heo/components/BlogPostCard.js | 8 +- themes/heo/components/BlogPostListScroll.js | 2 +- themes/heo/components/FloatDarkModeButton.js | 3 +- themes/heo/components/Hero.js | 34 +++---- themes/heo/components/InfoCard.js | 4 +- themes/heo/components/JumpToCommentButton.js | 3 +- themes/heo/components/JumpToTopButton.js | 3 +- themes/heo/components/MenuGroupCard.js | 6 +- themes/heo/components/MenuListSide.js | 8 +- themes/heo/components/MenuListTop.js | 6 +- themes/heo/components/NoticeBar.js | 3 +- themes/heo/components/TocDrawerButton.js | 3 +- themes/heo/components/TouchMeCard.js | 11 ++- themes/heo/config.js | 84 ++++++++-------- themes/hexo/components/ArticleAdjacent.js | 3 +- themes/hexo/components/ArticleCopyright.js | 2 +- themes/hexo/components/ArticleRecommend.js | 2 +- themes/hexo/components/BlogPostCard.js | 10 +- themes/hexo/components/BlogPostListScroll.js | 2 +- themes/hexo/components/FloatDarkModeButton.js | 3 +- themes/hexo/components/Hero.js | 6 +- themes/hexo/components/JumpToCommentButton.js | 3 +- themes/hexo/components/JumpToTopButton.js | 3 +- themes/hexo/components/MenuGroupCard.js | 7 +- themes/hexo/components/MenuListSide.js | 8 +- themes/hexo/components/MenuListTop.js | 10 +- themes/hexo/components/SideRight.js | 4 +- themes/hexo/components/TocDrawerButton.js | 3 +- themes/hexo/config.js | 50 +++++----- themes/hexo/index.js | 4 +- themes/landing/components/Features.js | 20 ++-- themes/landing/components/FeaturesBlocks.js | 29 +++--- themes/landing/components/Footer.js | 3 +- themes/landing/components/Header.js | 10 +- themes/landing/components/Hero.js | 19 ++-- themes/landing/components/MobileMenu.js | 9 +- themes/landing/components/ModalVideo.js | 5 +- themes/landing/components/Newsletter.js | 3 +- themes/landing/components/Testimonials.js | 13 +-- themes/landing/config.js | 96 +++++++++---------- themes/landing/index.js | 4 +- themes/matery/components/ArticleAdjacent.js | 3 +- themes/matery/components/ArticleCopyright.js | 2 +- themes/matery/components/ArticleRecommend.js | 2 +- themes/matery/components/BlogPostCard.js | 4 +- .../matery/components/BlogPostListScroll.js | 2 +- .../matery/components/FloatDarkModeButton.js | 3 +- themes/matery/components/Hero.js | 4 +- .../matery/components/JumpToCommentButton.js | 3 +- themes/matery/components/JumpToTopButton.js | 3 +- themes/matery/components/MenuGroupCard.js | 7 +- themes/matery/components/MenuList.js | 9 +- themes/matery/components/MenuListSide.js | 8 +- themes/matery/components/MenuListTop.js | 8 +- themes/matery/components/TocDrawerButton.js | 3 +- themes/matery/config.js | 40 ++++---- themes/matery/index.js | 4 +- themes/medium/components/BlogPostCard.js | 8 +- themes/medium/components/JumpToTopButton.js | 3 +- themes/medium/components/MenuBarMobile.js | 8 +- themes/medium/components/TopNavBar.js | 8 +- themes/medium/config.js | 26 ++--- themes/medium/index.js | 8 +- themes/nav/components/BlogPostListAll.js | 33 +++---- themes/nav/components/LogoBar.js | 2 +- themes/nav/components/MenuBarMobile.js | 8 +- themes/nav/config.js | 20 ++-- themes/nav/index.js | 6 +- themes/next/components/ArticleCopyright.js | 3 +- themes/next/components/ArticleDetail.js | 4 +- themes/next/components/BlogPostCard.js | 4 +- themes/next/components/BlogPostListScroll.js | 2 +- themes/next/components/FloatDarkModeButton.js | 3 +- themes/next/components/JumpToBottomButton.js | 3 +- themes/next/components/JumpToTopButton.js | 3 +- themes/next/components/MenuList.js | 6 +- themes/next/components/RecommendPosts.js | 3 +- themes/next/components/SideAreaLeft.js | 2 +- themes/next/components/SideAreaRight.js | 8 +- themes/next/components/StickyBar.js | 3 +- themes/next/components/TocDrawerButton.js | 3 +- themes/next/components/TopNav.js | 7 +- themes/next/config.js | 48 +++++----- themes/next/index.js | 4 +- themes/nobelium/components/Nav.js | 16 ++-- themes/nobelium/config.js | 16 ++-- themes/plog/components/BottomNav.js | 10 +- themes/plog/components/LogoBar.js | 2 +- themes/plog/components/Nav.js | 12 +-- themes/plog/config.js | 12 +-- themes/simple/components/ArticleInfo.js | 2 +- themes/simple/components/BlogItem.js | 2 +- themes/simple/components/Header.js | 2 +- themes/simple/components/MenuList.js | 8 +- themes/simple/components/TopBar.js | 5 +- themes/simple/config.js | 18 ++-- themes/simple/index.js | 2 +- 118 files changed, 570 insertions(+), 528 deletions(-) diff --git a/lib/config.js b/lib/config.js index 69c8fd14..46333d54 100644 --- a/lib/config.js +++ b/lib/config.js @@ -8,12 +8,13 @@ import { deepClone } from './utils' * 读取配置 * 1. 优先读取NotionConfig表 * 2. 其次读取环境变量 - * 3. 再读取blog.config.js文件 + * 3. 再读取blog.config.js / 或各个主题的CONFIG文件 * @param {*} key ; 参数名 * @param {*} defaultVal ; 参数不存在默认返回值 + * @param {*} extendConfig ; 参考配置对象{key:val},如果notion中找不到优先尝试在这里面查找 * @returns */ -export const siteConfig = (key, defaultVal = null) => { +export const siteConfig = (key, defaultVal = null, extendConfig) => { let global = null try { // eslint-disable-next-line react-hooks/rules-of-hooks @@ -45,6 +46,11 @@ export const siteConfig = (key, defaultVal = null) => { } } + // 其次 有传入的配置参考,则尝试读取 + if (!extendConfig) { + val = extendConfig[key] + } + // 其次 NOTION没有找到配置,则会读取blog.config.js文件 if (!val) { val = BLOG[key] diff --git a/themes/example/components/BlogListPage.js b/themes/example/components/BlogListPage.js index 66c33992..5ae2cf5c 100644 --- a/themes/example/components/BlogListPage.js +++ b/themes/example/components/BlogListPage.js @@ -17,7 +17,7 @@ export const BlogListPage = props => { const showNext = page < totalPage const pagePrefix = router.asPath.split('?')[0].replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '') - const showPageCover = CONFIG.POST_LIST_COVER + const showPageCover = siteConfig('EXAMPLE_POST_LIST_COVER', null, CONFIG) return (
diff --git a/themes/example/components/BlogListScroll.js b/themes/example/components/BlogListScroll.js index 686e2e72..e876f312 100644 --- a/themes/example/components/BlogListScroll.js +++ b/themes/example/components/BlogListScroll.js @@ -35,7 +35,7 @@ export const BlogListScroll = props => { handleGetMore() } }, 500)) - const showPageCover = CONFIG.POST_LIST_COVER + const showPageCover = siteConfig('EXAMPLE_POST_LIST_COVER', null, CONFIG) useEffect(() => { window.addEventListener('scroll', scrollTrigger) diff --git a/themes/example/components/BlogPostCard.js b/themes/example/components/BlogPostCard.js index a3ea0705..5b690743 100644 --- a/themes/example/components/BlogPostCard.js +++ b/themes/example/components/BlogPostCard.js @@ -5,7 +5,7 @@ import TwikooCommentCount from '@/components/TwikooCommentCount' import LazyImage from '@/components/LazyImage' const BlogPostCard = ({ post }) => { - const showPageCover = CONFIG.POST_LIST_COVER && post?.pageCoverThumbnail + const showPageCover = siteConfig('EXAMPLE_POST_LIST_COVER', null, CONFIG) && post?.pageCoverThumbnail return
diff --git a/themes/example/components/Nav.js b/themes/example/components/Nav.js index 851977c0..beb2c32e 100644 --- a/themes/example/components/Nav.js +++ b/themes/example/components/Nav.js @@ -13,10 +13,10 @@ export const Nav = (props) => { const { locale } = useGlobal() let links = [ - { id: 1, icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG.MENU_SEARCH }, - { id: 2, icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: CONFIG.MENU_ARCHIVE }, - { id: 3, icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: CONFIG.MENU_CATEGORY }, - { id: 4, icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: CONFIG.MENU_TAG } + { id: 1, icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: siteConfig('EXAMPLE_MENU_SEARCH', null, CONFIG) }, + { id: 2, icon: 'fas fa-archive', name: locale.NAV.ARCHIVE, to: '/archive', show: siteConfig('EXAMPLE_MENU_ARCHIVE', null, CONFIG) }, + { id: 3, icon: 'fas fa-folder', name: locale.COMMON.CATEGORY, to: '/category', show: siteConfig('EXAMPLE_MENU_CATEGORY', null, CONFIG) }, + { id: 4, icon: 'fas fa-tag', name: locale.COMMON.TAGS, to: '/tag', show: siteConfig('EXAMPLE_MENU_TAG', null, CONFIG) } ] if (customNav) { diff --git a/themes/example/config.js b/themes/example/config.js index 27b8a34d..181d3a93 100644 --- a/themes/example/config.js +++ b/themes/example/config.js @@ -3,12 +3,12 @@ */ const CONFIG = { // 菜单配置 - MENU_CATEGORY: true, // 显示分类 - MENU_TAG: true, // 显示标签 - MENU_ARCHIVE: true, // 显示归档 - MENU_SEARCH: true, // 显示搜索 + EXAMPLE_MENU_CATEGORY: true, // 显示分类 + EXAMPLE_MENU_TAG: true, // 显示标签 + EXAMPLE_MENU_ARCHIVE: true, // 显示归档 + EXAMPLE_MENU_SEARCH: true, // 显示搜索 - POST_LIST_COVER: true // 列表显示文章封面 + EXAMPLE_POST_LIST_COVER: true // 列表显示文章封面 } export default CONFIG diff --git a/themes/fukasawa/components/AsideLeft.js b/themes/fukasawa/components/AsideLeft.js index f3ca1e98..991b9ce4 100644 --- a/themes/fukasawa/components/AsideLeft.js +++ b/themes/fukasawa/components/AsideLeft.js @@ -54,7 +54,7 @@ function AsideLeft(props) { return