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