Skip to content

Commit

Permalink
配置文件读取规则
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Nov 19, 2024
1 parent ab21294 commit a5ee8f0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import BLOG from '@/blog.config'
import { useGlobal } from './global'
import { deepClone, isUrl } from './utils'

const getValue = (value, fallback) => (hasVal(value) ? fallback : value)
const hasVal = value => value !== undefined && value !== null

/**
* 读取配置顺序
* 1. 优先读取NotionConfig表
Expand Down Expand Up @@ -35,7 +38,9 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
case 'IS_TAG_COLOR_DISTINGUISHED':
case 'TAG_SORT_BY_COUNT':
case 'LINK':
return convertVal(extendConfig[key] || defaultVal || BLOG[key])
return convertVal(
getValue(extendConfig[key], getValue(defaultVal, BLOG[key]))
)
default:
}

Expand Down Expand Up @@ -79,16 +84,16 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
}

// 其次 有传入的extendConfig,则尝试读取
if (!val && extendConfig) {
if (!hasVal(val) && extendConfig) {
val = extendConfig[key]
}

// 其次 NOTION没有找到配置,则会读取blog.config.js文件
if (!val) {
if (!hasVal(val)) {
val = BLOG[key]
}

if (!val) {
if (!hasVal(val)) {
return defaultVal
}

Expand Down

0 comments on commit a5ee8f0

Please sign in to comment.