Skip to content

Commit 3f2de9e

Browse files
committed
feature: 配置文件整理
1 parent 7c68d1a commit 3f2de9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+284
-247
lines changed

blog.config.js

+105-70
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,108 @@
1-
const BLOG = {
2-
title: '小唐笔记', // 站点标题
3-
description: '分享编程技术与记录生活', // 站点描述
4-
author: 'tangly1024', // 作者
5-
bio: '一个普通的干饭人🍚', // 作者简介
6-
email: '[email protected]', // 联系邮箱
7-
link: 'https://tangly1024.com', // 网站地址
8-
keywords: ['Notion', '写作', '博客'], // 网站关键词
9-
lang: 'zh-CN', // ['zh-CN','en-US'] default lang => see /lib/lang.js for more.
10-
beian: '闽ICP备20010331号', // 备案号
11-
notionPageId: process.env.NOTION_PAGE_ID || 'bee1fccfa3bd47a1a7be83cc71372d83', // Important page_id!!!
12-
notionAccessToken: process.env.NOTION_ACCESS_TOKEN || '', // Useful if you prefer not to make your database public
13-
appearance: 'auto', // ['light', 'dark', 'auto'],
14-
font: 'font-serif tracking-wider subpixel-antialiased', // 文章字体 ['font-sans', 'font-serif', 'font-mono'] @see https://www.tailwindcss.cn/docs/font-family
15-
lightBackground: '#eeeeee', // use hex value, don't forget '#' e.g #fffefc
16-
darkBackground: '#111827', // use hex value, don't forget '#'
17-
path: '', // leave this empty unless you want to deploy in a folder
18-
since: 2020, // if leave this empty, current year will be used.
19-
postListStyle: 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载
20-
postsPerPage: 6, // post counts per page
21-
previewLines: 12, // 预览博客行数
22-
sortByDate: false,
23-
socialLink: { // 社交链接,如不需要展示可以留空白,例如 weibo:''
24-
weibo: 'https://weibo.com/tangly1024',
25-
twitter: 'https://twitter.com/troy1024_1',
26-
github: 'https://github.com/tangly1024',
27-
telegram: 'https://t.me/tangly_1024'
28-
},
29-
comment: { // 评论插件,支持 gitalk, utterances, cusdis
30-
provider: 'gitalk', // 不需要则留空白
31-
gitalkConfig: {
32-
repo: 'NotionNext', // The repository of store comments
33-
owner: 'tangly1024',
34-
admin: ['tangly1024'],
35-
clientID: process.env.GITALK_ID || 'be7864a16b693e256f8f',
36-
clientSecret: process.env.GITALK_SECRET || 'dbd0f6d9ceea8940f6ed20936b415274b8fe66a2',
37-
distractionFreeMode: false
38-
},
39-
cusdisConfig: {
40-
appId: '445ba48e-f751-487f-b22f-cdbe3310d28f', // data-app-id
41-
host: 'https://cusdis.com', // data-host, change this if you're using self-hosted version
42-
scriptSrc: 'https://cusdis.com/js/cusdis.es.js' // change this if you're using self-hosted version
43-
},
44-
utterancesConfig: {
45-
repo: 'tangly1024/NotionNext'
46-
},
47-
gitter: '', // gitter聊天室
48-
DaoVoiceId: '', // DaoVoice http://dashboard.daovoice.io/get-started
49-
TidioId: '' // https://www.tidio.com/
50-
},
51-
// --- 高级设置
52-
analytics: { // 文章访问量统计
53-
busuanzi: true, // 展示网站阅读量、访问数 see http://busuanzi.ibruce.info/
54-
provider: 'ga', // 支持 Google Analytics and Ackee, please fill with 'ga' or 'ackee', leave it empty to disable it.
55-
baiduAnalytics: 'f683ef76f06bb187cbed5546f6f28f28', // e.g only need xxxxx -> https://hm.baidu.com/hm.js?[xxxxx]
56-
cnzzAnalytics: '', // 站长统计id only need xxxxxxxx -> https://s9.cnzz.com/z_stat.php?id=[xxxxxxxx]&web_id=[xxxxxxx]
57-
gaConfig: {
58-
measurementId: 'G-68EK0W049N' // e.g: G-XXXXXXXXXX
59-
},
60-
ackeeConfig: {
61-
tracker: '', // e.g 'https://ackee.tangly1024.net/tracker.js'
62-
dataAckeeServer: '', // e.g https://ackee.tangly1024.net , don't end with a slash
63-
domainId: '' // e.g '0e2257a8-54d4-4847-91a1-0311ea48cc7b'
64-
}
65-
},
66-
seo: {
67-
googleSiteVerification: '' // Remove the value or replace it with your own google site verification code
68-
},
69-
googleAdsenseId: 'ca-pub-2708419466378217', // 谷歌广告ID
1+
// 注: 配置文件可以读取Vercel的环境变量,配置方式参考:https://docs.tangly1024.com/zh/features/personality
2+
const BLOG = mergeDeep(process.env, {
3+
TITLE: 'NotionNext BLOG', // 站点标题
4+
DESCRIPTION: '这是一个由NotionNext生成的站点', // 站点描述
5+
AUTHOR: 'tangly1024', // 作者
6+
BIO: '一个普通的干饭人🍚', // 作者简介
7+
LINK: 'https://tangly1024.com', // 网站地址
8+
NOTION_PAGE_ID: '02ab3b8678004aa69e9e415905ef32a5', // Important page_id!!!Duplicate Template from https://www.notion.so/tanghh/02ab3b8678004aa69e9e415905ef32a5
9+
NOTION_ACCESS_TOKEN: '', // Useful if you prefer not to make your database public
10+
KEYWORDS: 'Notion, 博客', // 网站关键词 英文逗号隔开
11+
LANG: 'zh-CN', // e.g 'zh-CN','en-US' see /lib/lang.js for more.
12+
BEI_AN: '', // 备案号 闽ICP备XXXXXXX
13+
SINCE: 2020, // if leave this empty, current year will be used.
14+
15+
APPEARANCE: 'auto', // ['light', 'dark', 'auto'],
16+
FONT: 'font-serif tracking-wider subpixel-antialiased', // 文章字体 ['font-sans', 'font-serif', 'font-mono'] @see https://www.tailwindcss.cn/docs/font-family
17+
BACKGROUND_LIGHT: '#eeeeee', // use hex value, don't forget '#' e.g #fffefc
18+
BACKGROUND_DARK: '#111827', // use hex value, don't forget '#'
19+
PATH: '', // leave this empty unless you want to deploy in a folder
20+
21+
POST_LIST_STYLE: 'page', // ['page','scroll] 文章列表样式:页码分页、单页滚动加载
22+
POST_PREVIEW_LINES: 12, // 预览博客行数
23+
POSTS_PER_PAGE: 6, // post counts per page
24+
POSTS_SORT_BY_DATE: false, // 是否强制按时间排序,否则默认由notion排序文章
25+
26+
// 社交链接,不需要可留空白,例如 CONTACT_WEIBO:''
27+
CONTACT_EMAIL: '[email protected]', // 联系邮箱
28+
CONTACT_WEIBO: 'https://weibo.com/tangly1024',
29+
CONTACT_TWITTER: 'https://twitter.com/troy1024_1',
30+
CONTACT_GITHUB: 'https://github.com/tangly1024',
31+
CONTACT_TELEGRAM: 'https://t.me/tangly_1024',
32+
33+
COMMENT_PROVIDER: '', // 支持 gitalk, utterances, cusdis
34+
35+
COMMENT_GITALK_REPO: '', // e.g NotionNext
36+
COMMENT_GITALK_OWNER: '', // e.g tangly1024
37+
COMMENT_GITALK_ADMIN: '', // e.g 'tangly1024'
38+
COMMENT_GITALK_CLIENT_ID: '',
39+
COMMENT_GITALK_CLIENT_SECRET: '',
40+
COMMENT_GITALK_DISTRACTION_FREE_MODE: false,
41+
42+
COMMENT_CUSDIS_APP_ID: '', // data-app-id
43+
COMMENT_CUSDIS_HOST: 'https://cusdis.com', // data-host, change this if you're using self-hosted version
44+
COMMENT_CUSDIS_SCRIPT_SRC: 'https://cusdis.com/js/cusdis.es.js', // change this if you're using self-hosted version
45+
46+
COMMENT_UTTERRANCES_REPO: '', // e.g 'tangly1024/NotionNext'
47+
48+
COMMENT_GITTER_ENABLE: false, // gitter see https://gitter.im/
49+
COMMENT_GITTER_ROOM: '', // gitter聊天室
50+
51+
COMMENT_DAO_VOICE_ENABLE: false, // DaoVoice see http://dashboard.daovoice.io/get-started
52+
COMMENT_DAO_VOICE_ID: '', // DaoVoice http://dashboard.daovoice.io/get-started
53+
54+
COMMENT_TIDIO_ENABLE: false, // https://www.tidio.com/
55+
COMMENT_TIDIO_ID: '', // [tidio_id] -> //code.tidio.co/[tidio_id].js
56+
57+
// 站点统计
58+
59+
ANALYTICS_BUSUANZI_ENABLE: true, // 展示网站阅读量、访问数 see http://busuanzi.ibruce.info/
60+
61+
ANALYTICS_BAIDU_ENABLE: false,
62+
ANALYTICS_BAIDU_ID: '', // e.g 只需要填写百度统计的id,[baidu_id] -> https://hm.baidu.com/hm.js?[baidu_id]
63+
64+
ANALYTICS_CNZZ_ENABLE: false,
65+
ANALYTICS_CNZZ_ID: '', // 只需要填写站长统计的id, [cnzz_id] -> https://s9.cnzz.com/z_stat.php?id=[cnzz_id]&web_id=[cnzz_id]
66+
67+
ANALYTICS_GOOGLE_ENABLE: false,
68+
ANALYTICS_GOOGLE_ID: '', // 谷歌Analytics的id e.g: G-XXXXXXXXXX
69+
70+
ANALYTICS_ACKEE_ENABLE: false,
71+
ANALYTICS_ACKEE_TRACKER: '', // e.g 'https://ackee.tangly1024.net/tracker.js'
72+
ANALYTICS_ACKEE_DATA_SERVER: '', // e.g https://ackee.tangly1024.net , don't end with a slash
73+
ANALYTICS_ACKEE_DOMAIN_ID: '', // e.g '0e2257a8-54d4-4847-91a1-0311ea48cc7b'
74+
75+
SEO_GOOGLE_SITE_VERIFICATION: '', // Remove the value or replace it with your own google site verification code
76+
77+
GOOGLE_ADSENSE_ENABLE: false,
78+
GOOGLE_ADSENSE_ID: process.env.GOOGLE_AD_ID, // 谷歌广告ID
7079
isProd: process.env.VERCEL_ENV === 'production'// distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
80+
})
81+
82+
/**
83+
* 深度合并两个对象
84+
* @param target
85+
* @param sources
86+
*/
87+
function mergeDeep (target, ...sources) {
88+
if (!sources.length) return target
89+
const source = sources.shift()
90+
91+
if (isObject(target) && isObject(source)) {
92+
for (const key in source) {
93+
if (isObject(source[key])) {
94+
if (!target[key]) Object.assign(target, { [key]: {} })
95+
mergeDeep(target[key], source[key])
96+
} else {
97+
Object.assign(target, { [key]: source[key] })
98+
}
99+
}
100+
}
101+
return mergeDeep(target, ...sources)
102+
}
103+
104+
function isObject (item) {
105+
return (item && typeof item === 'object' && !Array.isArray(item))
71106
}
72-
// export default BLOG
107+
73108
module.exports = BLOG

components/Ackee.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { useRouter } from 'next/router'
22
import useAckee from 'use-ackee'
3+
import BLOG from '@/blog.config'
34

4-
const Ackee = ({ ackeeServerUrl, ackeeDomainId }) => {
5+
const Ackee = () => {
6+
const ackeeServerUrl = BLOG.ANALYTICS_ACKEE_DATA_SERVER
7+
const ackeeDomainId = BLOG.ANALYTICS_ACKEE_DOMAIN_ID
58
const router = useRouter()
69
useAckee(
710
router.asPath,
8-
{ server: ackeeServerUrl, domainId: ackeeDomainId },
9-
{ detailed: false, ignoreLocalhost: true }
11+
{
12+
server: ackeeServerUrl,
13+
domainId: ackeeDomainId
14+
},
15+
{
16+
detailed: false,
17+
ignoreLocalhost: true
18+
}
1019
)
1120
return null
1221
}

components/Comment.js

+21-20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import dynamic from 'next/dynamic'
33
import { useRouter } from 'next/router'
44
import { useGlobal } from '@/lib/global'
55
import 'gitalk/dist/gitalk.css'
6+
import Tabs from '@/components/Tabs'
67

78
const GitalkComponent = dynamic(
89
() => {
@@ -28,44 +29,44 @@ const Comment = ({ frontMatter }) => {
2829
const { theme } = useGlobal()
2930

3031
return (
31-
BLOG.comment.provider !== '' && (
32-
<div className='comment mt-5 text-gray-800 dark:text-gray-300'>
33-
{BLOG.comment.provider === 'gitalk' && (<div className='m-10'>
32+
<div className='comment mt-5 text-gray-800 dark:text-gray-300'>
33+
<Tabs>
34+
{BLOG.COMMENT_GITALK_CLIENT_ID && (<div className='m-10' key='gitalk'>
3435
<GitalkComponent
3536
options={{
3637
id: frontMatter.id,
3738
title: frontMatter.title,
38-
clientID: BLOG.comment.gitalkConfig.clientID,
39-
clientSecret: BLOG.comment.gitalkConfig.clientSecret,
40-
repo: BLOG.comment.gitalkConfig.repo,
41-
owner: BLOG.comment.gitalkConfig.owner,
42-
admin: BLOG.comment.gitalkConfig.admin,
43-
distractionFreeMode: BLOG.comment.gitalkConfig.distractionFreeMode
39+
clientID: BLOG.COMMENT_GITALK_CLIENT_ID,
40+
clientSecret: BLOG.COMMENT_GITALK_CLIENT_SECRET,
41+
repo: BLOG.COMMENT_GITALK_REPO,
42+
owner: BLOG.COMMENT_GITALK_OWNER,
43+
admin: BLOG.COMMENT_GITALK_ADMIN.split(','),
44+
distractionFreeMode: BLOG.COMMENT_GITALK_DISTRACTION_FREE_MODE
4445
}}
4546
/>
4647
</div>)}
47-
{BLOG.comment.provider === 'utterances' && (<div className='m-10'>
48-
<UtterancesComponent issueTerm={frontMatter.id} className='px-2' />
49-
</div>
48+
{BLOG.COMMENT_UTTERRANCES_REPO && (<div className='m-10' key='utterance'>
49+
<UtterancesComponent issueTerm={frontMatter.id} className='px-2' />
50+
</div>
5051
)}
51-
{BLOG.comment.provider === 'cusdis' && (<>
52+
{BLOG.COMMENT_CUSDIS_APP_ID && (<>
5253
<script defer src='https://cusdis.com/js/widget/lang/zh-cn.js' />
53-
<div className='m-10'>
54+
<div className='m-10' key='cusdis'>
5455
<CusdisComponent
5556
attrs={{
56-
host: BLOG.comment.cusdisConfig.host,
57-
appId: BLOG.comment.cusdisConfig.appId,
57+
host: BLOG.COMMENT_CUSDIS_HOST,
58+
appId: BLOG.COMMENT_CUSDIS_APP_ID,
5859
pageId: frontMatter.id,
5960
pageTitle: frontMatter.title,
60-
pageUrl: BLOG.link + router.asPath,
61+
pageUrl: BLOG.LINK + router.asPath,
6162
theme: theme
6263
}}
63-
lang={BLOG.lang.toLowerCase()}
64+
lang={BLOG.LANG.toLowerCase()}
6465
/>
6566
</div>
6667
</>)}
67-
</div>
68-
)
68+
</Tabs>
69+
</div>
6970
)
7071
}
7172

components/CommonHead.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,30 @@ import BLOG from '@/blog.config'
22
import Head from 'next/head'
33

44
const CommonHead = ({ meta }) => {
5-
let url = BLOG.path.length ? `${BLOG.link}/${BLOG.path}` : BLOG.link
5+
let url = BLOG.PATH.length ? `${BLOG.LINK}/${BLOG.PATH}` : BLOG.LINK
66
if (meta) {
77
url = `${url}/${meta.slug}`
88
}
9-
const title = meta?.title || BLOG.title
10-
const description = meta?.description || BLOG.description
9+
const title = meta?.title || BLOG.TITLE
10+
const description = meta?.description || BLOG.DESCRIPTION
1111
const type = meta?.type || 'website'
12-
const keywords = meta?.tags || BLOG.keywords
12+
const keywords = meta?.tags || BLOG.KEYWORDS
1313

1414
return <Head>
1515
<title>{title}</title>
16-
<meta name='theme-color' content={BLOG.darkBackground} />
16+
<meta name='theme-color' content={BLOG.BACKGROUND_DARK} />
1717
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
1818
<meta name='robots' content='follow, index' />
1919
<meta charSet='UTF-8' />
20-
{BLOG.seo.googleSiteVerification && (
20+
{BLOG.SEO_GOOGLE_SITE_VERIFICATION && (
2121
<meta
2222
name='google-site-verification'
23-
content={BLOG.seo.googleSiteVerification}
23+
content={BLOG.SEO_GOOGLE_SITE_VERIFICATION}
2424
/>
2525
)}
26-
{keywords && (
27-
<meta name='keywords' content={keywords.join(', ')} />
28-
)}
26+
<meta name='keywords' content={keywords} />
2927
<meta name='description' content={description} />
30-
<meta property='og:locale' content={BLOG.lang} />
28+
<meta property='og:locale' content={BLOG.LANG} />
3129
<meta property='og:title' content={title} />
3230
<meta property='og:description' content={description} />
3331
<meta property='og:url' content={url}
@@ -42,7 +40,7 @@ const CommonHead = ({ meta }) => {
4240
property='article:published_time'
4341
content={meta.date || meta.createdTime}
4442
/>
45-
<meta property='article:author' content={BLOG.author} />
43+
<meta property='article:author' content={BLOG.AUTHOR} />
4644
</>
4745
)}
4846
</Head>

0 commit comments

Comments
 (0)