mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-08 15:10:37 +00:00
修复部分NOTION_CONFIG读取问题
This commit is contained in:
@@ -14,15 +14,38 @@ import { deepClone } from './utils'
|
||||
* @param {*} extendConfig ; 参考配置对象{key:val},如果notion中找不到优先尝试在这里面查找
|
||||
* @returns
|
||||
*/
|
||||
export const siteConfig = (key, defaultVal = null, extendConfig = null) => {
|
||||
let global = null
|
||||
export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
|
||||
if (!key) {
|
||||
return null
|
||||
}
|
||||
|
||||
// 特殊配置处理;某些配置只在服务端生效;而Global的NOTION_CONFIG仅限前端组件使用,因此需要从extendConfig中读取
|
||||
switch (key) {
|
||||
case 'NEXT_REVALIDATE_SECOND':
|
||||
case 'POST_RECOMMEND_COUNT':
|
||||
case 'IMAGE_COMPRESS_WIDTH':
|
||||
case 'PSEUDO_STATIC':
|
||||
case 'POSTS_SORT_BY':
|
||||
case 'POSTS_PER_PAGE':
|
||||
case 'POST_PREVIEW_LINES':
|
||||
case 'POST_URL_PREFIX':
|
||||
case 'POST_LIST_STYLE':
|
||||
case 'POST_LIST_PREVIEW':
|
||||
case 'POST_URL_PREFIX_MAPPING_CATEGORY':
|
||||
return convertVal(extendConfig[key] || defaultVal || BLOG[key])
|
||||
default:
|
||||
}
|
||||
|
||||
let global = {}
|
||||
try {
|
||||
const isClient = typeof window !== 'undefined'
|
||||
// const isClient = typeof window !== 'undefined'
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
global = isClient ? useGlobal() : {}
|
||||
global = useGlobal()
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
// global = useGlobal()
|
||||
} catch (error) {}
|
||||
} catch (error) {
|
||||
console.warn('SiteConfig警告', key, error)
|
||||
}
|
||||
|
||||
// 首先 配置最优先读取NOTION中的表格配置
|
||||
let val = null
|
||||
@@ -66,6 +89,16 @@ export const siteConfig = (key, defaultVal = null, extendConfig = null) => {
|
||||
}
|
||||
|
||||
// 从Notion_CONFIG读取的配置通常都是字符串,适当转义
|
||||
return convertVal(val)
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置默认都是string类型;
|
||||
* 识别配置的值是否数字、布尔、[]数组,若是则转成对应类型
|
||||
* @param {*} val
|
||||
* @returns
|
||||
*/
|
||||
export const convertVal = val => {
|
||||
if (typeof val === 'string') {
|
||||
// 解析布尔
|
||||
if (val === 'true' || val === 'false') {
|
||||
|
||||
Reference in New Issue
Block a user