63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
const DEFAULTS = {
|
|
title: 'RC707的工具箱',
|
|
icp: '苏ICP备2022013040号-1',
|
|
gaId: '',
|
|
jinrishiciSdkUrl: '',
|
|
}
|
|
|
|
function getRuntimeConfig() {
|
|
if (typeof window !== 'undefined' && window.__SITE_CONFIG__) {
|
|
return window.__SITE_CONFIG__
|
|
}
|
|
return {}
|
|
}
|
|
|
|
function getConfigValue(runtimeKey, envKey, defaultValue) {
|
|
const runtime = getRuntimeConfig()
|
|
if (Object.prototype.hasOwnProperty.call(runtime, runtimeKey)) {
|
|
return runtime[runtimeKey]
|
|
}
|
|
const fromEnv = import.meta.env[envKey]
|
|
if (fromEnv != null) {
|
|
return fromEnv
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
export function getSiteTitle() {
|
|
const value = getConfigValue('title', 'VITE_APP_TITLE', DEFAULTS.title)
|
|
return value || DEFAULTS.title
|
|
}
|
|
|
|
export function getSiteIcp() {
|
|
return getConfigValue('icp', 'VITE_APP_ICP', DEFAULTS.icp)
|
|
}
|
|
|
|
export function getGaMeasurementId() {
|
|
return getConfigValue('gaId', 'VITE_GA_MEASUREMENT_ID', DEFAULTS.gaId)
|
|
}
|
|
|
|
export function getJinrishiciSdkUrl() {
|
|
return getConfigValue('jinrishiciSdkUrl', 'VITE_JINRISHICI_SDK_URL', DEFAULTS.jinrishiciSdkUrl)
|
|
}
|
|
|
|
export function getPageTitle(suffix) {
|
|
const base = getSiteTitle()
|
|
return suffix ? `${base}-${suffix}` : base
|
|
}
|
|
|
|
export const siteConfig = {
|
|
get title() {
|
|
return getSiteTitle()
|
|
},
|
|
get icp() {
|
|
return getSiteIcp()
|
|
},
|
|
get gaMeasurementId() {
|
|
return getGaMeasurementId()
|
|
},
|
|
get jinrishiciSdkUrl() {
|
|
return getJinrishiciSdkUrl()
|
|
},
|
|
}
|