diff --git a/blog.config.js b/blog.config.js
index 80b8ddbd..fab32f70 100644
--- a/blog.config.js
+++ b/blog.config.js
@@ -304,13 +304,11 @@ const BLOG = {
// HOSTNAME: Webmention绑定之网域,通常即为本站网址
// TWITTER_USERNAME: 评论显示区域需要的资讯
// TOKEN: Webmention的API token
- COMMENT_WEBMENTION: {
- ENABLE: process.env.NEXT_PUBLIC_WEBMENTION_ENABLE || false,
- AUTH: process.env.NEXT_PUBLIC_WEBMENTION_AUTH || '',
- HOSTNAME: process.env.NEXT_PUBLIC_WEBMENTION_HOSTNAME || '',
- TWITTER_USERNAME: process.env.NEXT_PUBLIC_TWITTER_USERNAME || '',
- TOKEN: process.env.NEXT_PUBLIC_WEBMENTION_TOKEN || ''
- },
+ COMMENT_WEBMENTION_ENABLE: process.env.NEXT_PUBLIC_WEBMENTION_ENABLE || false,
+ COMMENT_WEBMENTION_AUTH: process.env.NEXT_PUBLIC_WEBMENTION_AUTH || '',
+ COMMENT_WEBMENTION_HOSTNAME: process.env.NEXT_PUBLIC_WEBMENTION_HOSTNAME || '',
+ COMMENT_WEBMENTION_TWITTER_USERNAME: process.env.NEXT_PUBLIC_TWITTER_USERNAME || '',
+ COMMENT_WEBMENTION_TOKEN: process.env.NEXT_PUBLIC_WEBMENTION_TOKEN || '',
// <---- 评论插件
diff --git a/components/Comment.js b/components/Comment.js
index 9359ed36..0e31e23c 100644
--- a/components/Comment.js
+++ b/components/Comment.js
@@ -60,7 +60,7 @@ const ValineComponent = dynamic(() => import('@/components/ValineComponent'), {
*/
export const commentEnable = BLOG.COMMENT_TWIKOO_ENV_ID || BLOG.COMMENT_WALINE_SERVER_URL || BLOG.COMMENT_VALINE_APP_ID ||
BLOG.COMMENT_GISCUS_REPO || BLOG.COMMENT_CUSDIS_APP_ID || BLOG.COMMENT_UTTERRANCES_REPO ||
- BLOG.COMMENT_GITALK_CLIENT_ID || BLOG.COMMENT_WEBMENTION.ENABLE
+ BLOG.COMMENT_GITALK_CLIENT_ID || BLOG.COMMENT_WEBMENTION_ENABLE
/**
* 评论组件
@@ -119,7 +119,7 @@ const Comment = ({ siteInfo, frontMatter, className }) => {
)}
- {BLOG.COMMENT_WEBMENTION.ENABLE && (
+ {BLOG.COMMENT_WEBMENTION_ENABLE && (
)}
diff --git a/components/CommonHead.js b/components/CommonHead.js
index d2b3d1b5..1aeb36dd 100644
--- a/components/CommonHead.js
+++ b/components/CommonHead.js
@@ -2,7 +2,7 @@ import { siteConfig } from '@/lib/config'
import Head from 'next/head'
const CommonHead = ({ meta, children }) => {
- let url = siteConfig('PATH')?.length ? `${siteConfig('LINK')}/${siteConfig('SUB_PATH','')}` : siteConfig('LINK')
+ let url = siteConfig('PATH')?.length ? `${siteConfig('LINK')}/${siteConfig('SUB_PATH', '')}` : siteConfig('LINK')
let image
if (meta) {
url = `${url}/${meta.slug}`
@@ -13,7 +13,7 @@ const CommonHead = ({ meta, children }) => {
const type = meta?.type || 'website'
const keywords = meta?.tags || siteConfig('KEYWORDS')
const lang = siteConfig('LANG').replace('-', '_') // Facebook OpenGraph 要 zh_CN 這樣的格式才抓得到語言
- const category = meta?.category || siteConfig('KEYWORDS') || '軟體科技' // section 主要是像是 category 這樣的分類,Facebook 用這個來抓連結的分類
+ const category = meta?.category || siteConfig('KEYWORDS') // section 主要是像是 category 這樣的分類,Facebook 用這個來抓連結的分類
return (
@@ -42,15 +42,15 @@ const CommonHead = ({ meta, children }) => {
- {siteConfig('COMMENT_WEBMENTION').ENABLE && (
+ {siteConfig('COMMENT_WEBMENTION_ENABLE') && (
<>
-
-
+
+
>
)}
- {siteConfig('COMMENT_WEBMENTION').ENABLE && siteConfig('COMMENT_WEBMENTION').AUTH !== '' && (
-
+ {siteConfig('COMMENT_WEBMENTION_ENABLE') && siteConfig('COMMENT_WEBMENTION_AUTH') !== '' && (
+
)}
{JSON.parse(siteConfig('ANALYTICS_BUSUANZI_ENABLE')) &&
}
diff --git a/components/WebMention.js b/components/WebMention.js
index 375a0141..da52b8b7 100644
--- a/components/WebMention.js
+++ b/components/WebMention.js
@@ -78,7 +78,7 @@ const WebmentionReplies = ({ target }) => {
const [mentions, setMentions] = useState([])
const fetchMentions = async (target) =>
fetch(
- `https://webmention.io/api/mentions.jf2?per-page=500&target=${encodeURIComponent(target)}&token=${BLOG.COMMENT_WEBMENTION.TOKEN}`
+ `https://webmention.io/api/mentions.jf2?per-page=500&target=${encodeURIComponent(target)}&token=${BLOG.COMMENT_WEBMENTION_TOKEN}`
).then((response) => (response.json ? response.json() : response))
useEffect(() => {
async function getMentions() {
@@ -137,8 +137,8 @@ const WebmentionReplies = ({ target }) => {
const WebMentionBlock = ({ frontMatter }) => {
const router = useRouter()
- const url = `https://${BLOG.COMMENT_WEBMENTION.HOSTNAME}${router.asPath}`
- const tweet = `${frontMatter.title} by @${BLOG.COMMENT_WEBMENTION.TWITTER_USERNAME} ${url}`
+ const url = `https://${BLOG.COMMENT_WEBMENTION_HOSTNAME}${router.asPath}`
+ const tweet = `${frontMatter.title} by @${BLOG.COMMENT_WEBMENTION_TWITTER_USERNAME} ${url}`
return (
diff --git a/lib/config.js b/lib/config.js
index 46333d54..863bfde2 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -47,7 +47,7 @@ export const siteConfig = (key, defaultVal = null, extendConfig) => {
}
// 其次 有传入的配置参考,则尝试读取
- if (!extendConfig) {
+ if (!val && extendConfig) {
val = extendConfig[key]
}
@@ -55,11 +55,21 @@ export const siteConfig = (key, defaultVal = null, extendConfig) => {
if (!val) {
val = BLOG[key]
}
+
if (!val) {
- val = defaultVal
+ return defaultVal
+ } else {
+ if (typeof val === 'string') {
+ return val;
+ } else {
+ try {
+ return JSON.parse(val);
+ } catch (error) {
+ // 如果值是一个字符串但不是有效的 JSON 格式,直接返回字符串
+ return val;
+ }
+ }
}
- // console.log('实际配置', key, val)
- return val
}
/**
diff --git a/themes/landing/components/Features.js b/themes/landing/components/Features.js
index 8ec10fa3..c0e403b5 100644
--- a/themes/landing/components/Features.js
+++ b/themes/landing/components/Features.js
@@ -5,6 +5,7 @@ import { useState, useRef, useEffect } from 'react'
import { Transition } from '@headlessui/react'
import CONFIG from '../config'
import LazyImage from '@/components/LazyImage'
+import { siteConfig } from '@/lib/config'
// import FeaturesElement from '@/public/images/features-element.png'
export default function Features() {
diff --git a/themes/landing/index.js b/themes/landing/index.js
index a15710e1..b7f81495 100644
--- a/themes/landing/index.js
+++ b/themes/landing/index.js
@@ -7,7 +7,6 @@
* 2. 内容大部分是在此文件中写死,notion数据从props参数中传进来
* 3. 您可在此网站找到更多喜欢的组件 https://www.tailwind-kit.com/
*/
-/* eslint-disable*/
import NotionPage from '@/components/NotionPage'
import Header from './components/Header'
import Footer from './components/Footer'
@@ -21,11 +20,7 @@ import { useRouter } from 'next/router'
import CONFIG from './config'
import Loading from '@/components/Loading'
import { isBrowser } from '@/lib/utils'
-
-/**
- * 这是个配置文件,可以方便在此统一配置信息
- */
-const THEME_CONFIG = { THEME: 'landing' }
+import { siteConfig } from '@/lib/config'
/**
* 布局框架
@@ -35,9 +30,9 @@ const THEME_CONFIG = { THEME: 'landing' }
* @returns
*/
const LayoutBase = (props) => {
- const { meta, siteInfo, children } = props
+ const { meta, siteInfo, children } = props
- return
+ return
{/* 网页SEO */}
@@ -55,14 +50,13 @@ const LayoutBase = (props) => {
}
-
/**
* 首页布局
* @param {*} props
* @returns
*/
const LayoutIndex = (props) => {
- return (
+ return (
@@ -70,7 +64,7 @@ const LayoutIndex = (props) => {
- )
+ )
}
/**
@@ -79,22 +73,20 @@ const LayoutIndex = (props) => {
* @returns
*/
const LayoutSlug = (props) => {
- // 如果 是 /article/[slug] 的文章路径则进行重定向到另一个域名
- const router = useRouter()
- if (JSON.parse(siteConfig('LANDING_POST_REDIRECT_ENABLE', null, CONFIG)) && isBrowser && router.route == '/[prefix]/[slug]') {
- const redirectUrl = siteConfig('LANDING_POST_REDIRECT_URL', null, CONFIG) + router.asPath.replace('?theme=landing', '')
- router.push(redirectUrl)
- return
- }
+ // 如果 是 /article/[slug] 的文章路径则进行重定向到另一个域名
+ const router = useRouter()
+ if (JSON.parse(siteConfig('LANDING_POST_REDIRECT_ENABLE', null, CONFIG)) && isBrowser && router.route === '/[prefix]/[slug]') {
+ const redirectUrl = siteConfig('LANDING_POST_REDIRECT_URL', null, CONFIG) + router.asPath.replace('?theme=landing', '')
+ router.push(redirectUrl)
+ return
+ }
- return
+ return
-
-
}
// 其他布局暂时留空
@@ -106,13 +98,13 @@ const LayoutPostList = (props) =>
const LayoutTagIndex = (props) =>
export {
- THEME_CONFIG,
- LayoutIndex,
- LayoutSearch,
- LayoutArchive,
- LayoutSlug,
- Layout404,
- LayoutPostList,
- LayoutCategoryIndex,
- LayoutTagIndex
+ CONFIG as THEME_CONFIG,
+ LayoutIndex,
+ LayoutSearch,
+ LayoutArchive,
+ LayoutSlug,
+ Layout404,
+ LayoutPostList,
+ LayoutCategoryIndex,
+ LayoutTagIndex
}
diff --git a/themes/nav/components/BlogArchiveItem.js b/themes/nav/components/BlogArchiveItem.js
index 4fc76cae..efd67565 100755
--- a/themes/nav/components/BlogArchiveItem.js
+++ b/themes/nav/components/BlogArchiveItem.js
@@ -1,3 +1,4 @@
+import { siteConfig } from '@/lib/config'
import Link from 'next/link'
/**
diff --git a/themes/nobelium/components/Nav.js b/themes/nobelium/components/Nav.js
index 82d85f21..b050a0f5 100644
--- a/themes/nobelium/components/Nav.js
+++ b/themes/nobelium/components/Nav.js
@@ -61,7 +61,7 @@ const Nav = props => {
)
: (
-
+
{siteConfig('TITLE')}
{/* ,{' '}{siteConfig('HOME_BANNER_IMAGE')} */}