Files
NotionNext/lib/config.js
2023-11-01 18:40:00 +08:00

50 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client'
import BLOG from '@/blog.config'
import { useGlobal } from './global'
/**
* 读取配置
* @param {*} key
* @returns
*/
export const siteConfig = (key) => {
let global = null
try {
// eslint-disable-next-line react-hooks/rules-of-hooks
global = useGlobal()
} catch (error) {}
// 首先 配置最优先读取NOTION中的表格配置
let val = null
let siteInfo = null
if (global) {
val = global.NOTION_CONFIG?.[key]
siteInfo = global.siteInfo
console.log('当前变量', key, val)
}
if (!val) {
// 这里针对部分key做一些兼容处理
switch (key) {
case 'HOME_BANNER_IMAGE':
val = siteInfo?.pageCover // 封面图取Notion的封面
break
case 'AVATAR':
val = siteInfo?.icon // 封面图取Notion的封面
break
case 'TITLE':
val = siteConfig('TITLE') // 标题取Notion中的标题
break
}
}
// 其次 NOTION没有找到配置则会读取blog.config.js文件
if (!val) {
val = BLOG[key]
}
console.log('配置', key, val)
return val
}