Skip to content

Commit

Permalink
Merge pull request #1619 from tangly1024/release/4.1.0
Browse files Browse the repository at this point in the history
Release/4.1.0
  • Loading branch information
tangly1024 authored Nov 10, 2023
2 parents 56c35d2 + c5e526d commit 1965fff
Show file tree
Hide file tree
Showing 358 changed files with 2,385 additions and 2,170 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=4.0.18
NEXT_PUBLIC_VERSION=4.1.0
14 changes: 6 additions & 8 deletions blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const BLOG = {
process.env.NOTION_PAGE_ID || '02ab3b8678004aa69e9e415905ef32a5',
PSEUDO_STATIC: process.env.NEXT_PUBLIC_PSEUDO_STATIC || false, // 伪静态路径,开启后所有文章URL都以 .html 结尾。
NEXT_REVALIDATE_SECOND: process.env.NEXT_PUBLIC_REVALIDATE_SECOND || 5, // 更新内容缓存间隔 单位(秒);即每个页面有5秒的纯静态期、此期间无论多少次访问都不会抓取notion数据;调大该值有助于节省Vercel资源、同时提升访问速率,但也会使文章更新有延迟。
THEME: process.env.NEXT_PUBLIC_THEME || 'hexo', // 当前主题,在themes文件夹下可找到所有支持的主题;主题名称就是文件夹名,例如 example,fukasawa,gitbook,heo,hexo,landing,matery,medium,next,nobelium,plog,simple
THEME: process.env.NEXT_PUBLIC_THEME || 'simple', // 当前主题,在themes文件夹下可找到所有支持的主题;主题名称就是文件夹名,例如 example,fukasawa,gitbook,heo,hexo,landing,matery,medium,next,nobelium,plog,simple
THEME_SWITCH: process.env.NEXT_PUBLIC_THEME_SWITCH || false, // 是否显示切换主题按钮
LANG: process.env.NEXT_PUBLIC_LANG || 'zh-CN', // e.g 'zh-CN','en-US' see /lib/lang.js for more.
SINCE: 2021, // e.g if leave this empty, current year will be used.
Expand Down Expand Up @@ -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 || '',

// <---- 评论插件

Expand Down
40 changes: 21 additions & 19 deletions components/Ackee.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
'use strict'

import { useEffect } from 'react'
import BLOG from '@/blog.config'
import { loadExternalResource } from '@/lib/utils'
import { useRouter } from 'next/router'
import { siteConfig } from '@/lib/config'
const Ackee = () => {
const router = useRouter()
const server = siteConfig('ANALYTICS_ACKEE_DATA_SERVER')
const domainId = siteConfig('ANALYTICS_ACKEE_DOMAIN_ID')

// 或者使用其他依赖数组,根据需要执行 handleAckee
useEffect(() => {
handleAckeeCallback()
}, [router])

// handleAckee 函数
const handleAckeeCallback = () => {
handleAckee(
router.asPath,
{
server: BLOG.ANALYTICS_ACKEE_DATA_SERVER,
domainId: BLOG.ANALYTICS_ACKEE_DOMAIN_ID
server: server,
domainId: domainId
},
{
/*
* Enable or disable tracking of personal data.
* We recommend to ask the user for permission before turning this option on.
*/
* Enable or disable tracking of personal data.
* We recommend to ask the user for permission before turning this option on.
*/
detailed: true,
/*
* Enable or disable tracking when on localhost.
*/
* Enable or disable tracking when on localhost.
*/
ignoreLocalhost: false,
/*
* Enable or disable the tracking of your own visits.
* This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header.
* Some browsers strictly block third-party cookies. The option won't have an impact when this is the case.
*/
* Enable or disable the tracking of your own visits.
* This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header.
* Some browsers strictly block third-party cookies. The option won't have an impact when this is the case.
*/
ignoreOwnVisits: false
}
)
}

// 或者使用其他依赖数组,根据需要执行 handleAckee
useEffect(() => {
handleAckeeCallback()
}, [router])

return null
}

Expand All @@ -53,8 +55,8 @@ export default Ackee
* @param {Object} environment - Object containing the URL of the Ackee server and the domain id.
* @param {?Object} options - Ackee options.
*/
const handleAckee = async function(pathname, environment, options = {}) {
await loadExternalResource(BLOG.ANALYTICS_ACKEE_TRACKER, 'js')
const handleAckee = async function (pathname, environment, options = {}) {
await loadExternalResource(siteConfig('ANALYTICS_ACKEE_TRACKER'), 'js')
const ackeeTracker = window.ackeeTracker

const instance = ackeeTracker?.create(environment.server, options)
Expand Down
10 changes: 5 additions & 5 deletions components/AlgoliaSearchModal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState, useImperativeHandle, useRef } from 'react'
import BLOG from '@/blog.config'
import algoliasearch from 'algoliasearch'
import replaceSearchResult from '@/components/Mark'
import Link from 'next/link'
import { useGlobal } from '@/lib/global'
import throttle from 'lodash/throttle'
import { siteConfig } from '@/lib/config'

/**
* 结合 Algolia 实现的弹出式搜索框
Expand All @@ -31,8 +31,8 @@ export default function AlgoliaSearchModal({ cRef }) {
}
})

const client = algoliasearch(BLOG.ALGOLIA_APP_ID, BLOG.ALGOLIA_SEARCH_ONLY_APP_KEY)
const index = client.initIndex(BLOG.ALGOLIA_INDEX)
const client = algoliasearch(siteConfig('ALGOLIA_APP_ID'), siteConfig('ALGOLIA_SEARCH_ONLY_APP_KEY'))
const index = client.initIndex(siteConfig('ALGOLIA_INDEX'))

/**
* 搜索
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function AlgoliaSearchModal({ cRef }) {
setIsModalOpen(false)
}

if (!BLOG.ALGOLIA_APP_ID) {
if (!siteConfig('ALGOLIA_APP_ID')) {
return <></>
}

Expand All @@ -123,7 +123,7 @@ export default function AlgoliaSearchModal({ cRef }) {
<ul>
{searchResults.map((result) => (
<li key={result.objectID} className="replace my-2">
<a href={`${BLOG.SUB_PATH}/${result.slug}`} className="font-bold hover:text-blue-600 text-black dark:text-gray-200">
<a href={`${siteConfig('SUB_PATH')}/${result.slug}`} className="font-bold hover:text-blue-600 text-black dark:text-gray-200">
{result.title}
</a>
</li>
Expand Down
21 changes: 15 additions & 6 deletions components/Artalk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import { loadExternalResource } from '@/lib/utils'
// import { loadExternalResource } from '@/lib/utils'
import { useEffect } from 'react'
Expand All @@ -11,17 +11,26 @@ import { useEffect } from 'react'
*/

const Artalk = ({ siteInfo }) => {
const artalkCss = siteConfig('COMMENT_ARTALK_CSS')
const artalkServer = siteConfig('COMMENT_ARTALK_SERVER')
const artalkLocale = siteConfig('LANG')
const site = siteConfig('TITLE')

useEffect(() => {
loadExternalResource(BLOG.COMMENT_ARTALK_CSS, 'css')
initArtalk()
}, [])

const initArtalk = async () => {
await loadExternalResource(artalkCss, 'css')
window?.Artalk?.init({
server: BLOG.COMMENT_ARTALK_SERVER, // 后端地址
server: artalkServer, // 后端地址
el: '#artalk', // 容器元素
locale: BLOG.LANG,
locale: artalkLocale,
// pageKey: '/post/1', // 固定链接 (留空自动获取)
// pageTitle: '关于引入 Artalk 的这档子事', // 页面标题 (留空自动获取)
site: siteInfo?.title // 你的站点名
site: site // 你的站点名
})
}, [])
}
return (
<div id="artalk"></div>
)
Expand Down
8 changes: 4 additions & 4 deletions components/ChatBase.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'

/**
* 这是一个嵌入组件,可以在任意位置全屏显示您的chat-base对话框
* 暂时没有页面引用
* 因为您可以直接用内嵌网页的方式放入您的notion中 https://www.chatbase.co/chatbot-iframe/${BLOG.CHATBASE_ID}
* 因为您可以直接用内嵌网页的方式放入您的notion中 https://www.chatbase.co/chatbot-iframe/${siteConfig('CHATBASE_ID')}
*/
export default function ChatBase() {
if (!BLOG.CHATBASE_ID) {
if (!siteConfig('CHATBASE_ID')) {
return <></>
}

return <iframe
src={`https://www.chatbase.co/chatbot-iframe/${BLOG.CHATBASE_ID}`}
src={`https://www.chatbase.co/chatbot-iframe/${siteConfig('CHATBASE_ID')}`}
width="100%"
style={{ height: '100%', minHeight: '700px' }}
frameborder="0"
Expand Down
30 changes: 12 additions & 18 deletions components/Comment.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import BLOG from '@/blog.config'
import dynamic from 'next/dynamic'
import Tabs from '@/components/Tabs'
import { isBrowser } from '@/lib/utils'
import { useRouter } from 'next/router'
import Artalk from './Artalk'
import { siteConfig } from '@/lib/config'

const WalineComponent = dynamic(
() => {
Expand Down Expand Up @@ -55,13 +55,6 @@ const ValineComponent = dynamic(() => import('@/components/ValineComponent'), {
ssr: false
})

/**
* 是否有评论
*/
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

/**
* 评论组件
* @param {*} param0
Expand All @@ -70,6 +63,7 @@ BLOG.COMMENT_GISCUS_REPO || BLOG.COMMENT_CUSDIS_APP_ID || BLOG.COMMENT_UTTERRANC
const Comment = ({ siteInfo, frontMatter, className }) => {
const router = useRouter()

// 当连接中有特殊参数时跳转到评论区
if (isBrowser && ('giscus' in router.query || router.query.target === 'comment')) {
setTimeout(() => {
const url = router.asPath.replace('?target=comment', '')
Expand All @@ -85,41 +79,41 @@ const Comment = ({ siteInfo, frontMatter, className }) => {
return (
<div key={frontMatter?.id} id='comment' className={`comment mt-5 text-gray-800 dark:text-gray-300 ${className || ''}`}>
<Tabs>
{BLOG.COMMENT_ARTALK_SERVER && (<div key='Artalk'>
<Artalk siteInfo={siteInfo} />
{siteConfig('COMMENT_ARTALK_SERVER') && (<div key='Artalk'>
<Artalk />
</div>)}

{BLOG.COMMENT_TWIKOO_ENV_ID && (<div key='Twikoo'>
{siteConfig('COMMENT_TWIKOO_ENV_ID') && (<div key='Twikoo'>
<TwikooCompenent />
</div>)}

{BLOG.COMMENT_WALINE_SERVER_URL && (<div key='Waline'>
{siteConfig('COMMENT_WALINE_SERVER_URL') && (<div key='Waline'>
<WalineComponent />
</div>)}

{BLOG.COMMENT_VALINE_APP_ID && (<div key='Valine' name='reply'>
{siteConfig('COMMENT_VALINE_APP_ID') && (<div key='Valine' name='reply'>
<ValineComponent path={frontMatter.id} />
</div>)}

{BLOG.COMMENT_GISCUS_REPO && (
{siteConfig('COMMENT_GISCUS_REPO') && (
<div key="Giscus">
<GiscusComponent className="px-2" />
</div>
)}

{BLOG.COMMENT_CUSDIS_APP_ID && (<div key='Cusdis'>
{siteConfig('COMMENT_CUSDIS_APP_ID') && (<div key='Cusdis'>
<CusdisComponent frontMatter={frontMatter} />
</div>)}

{BLOG.COMMENT_UTTERRANCES_REPO && (<div key='Utterance'>
{siteConfig('COMMENT_UTTERRANCES_REPO') && (<div key='Utterance'>
<UtterancesComponent issueTerm={frontMatter.id} className='px-2' />
</div>)}

{BLOG.COMMENT_GITALK_CLIENT_ID && (<div key='GitTalk'>
{siteConfig('COMMENT_GITALK_CLIENT_ID') && (<div key='GitTalk'>
<GitalkComponent frontMatter={frontMatter} />
</div>)}

{BLOG.COMMENT_WEBMENTION.ENABLE && (<div key='WebMention'>
{siteConfig('COMMENT_WEBMENTION_ENABLE') && (<div key='WebMention'>
<WebMentionComponent frontMatter={frontMatter} className="px-2" />
</div>)}
</Tabs>
Expand Down
40 changes: 20 additions & 20 deletions components/CommonHead.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
import BLOG from '@/blog.config'
import { siteConfig } from '@/lib/config'
import Head from 'next/head'

const CommonHead = ({ meta, children }) => {
let url = BLOG?.PATH?.length ? `${BLOG.LINK}/${BLOG.SUB_PATH}` : BLOG.LINK
let url = siteConfig('PATH')?.length ? `${siteConfig('LINK')}/${siteConfig('SUB_PATH', '')}` : siteConfig('LINK')
let image
if (meta) {
url = `${url}/${meta.slug}`
image = meta.image || '/bg_image.jpg'
}
const title = meta?.title || BLOG.TITLE
const description = meta?.description || BLOG.DESCRIPTION
const title = meta?.title || siteConfig('TITLE')
const description = meta?.description || siteConfig('DESCRIPTION')
const type = meta?.type || 'website'
const keywords = meta?.tags || BLOG.KEYWORDS
const lang = BLOG.LANG.replace('-', '_') // Facebook OpenGraph 要 zh_CN 這樣的格式才抓得到語言
const category = meta?.category || BLOG.KEYWORDS || '軟體科技' // section 主要是像是 category 這樣的分類,Facebook 用這個來抓連結的分類
const keywords = meta?.tags || siteConfig('KEYWORDS')
const lang = siteConfig('LANG').replace('-', '_') // Facebook OpenGraph 要 zh_CN 這樣的格式才抓得到語言
const category = meta?.category || siteConfig('KEYWORDS') // section 主要是像是 category 這樣的分類,Facebook 用這個來抓連結的分類

return (
<Head>
<title>{title}</title>
<meta name="theme-color" content={BLOG.BACKGROUND_DARK} />
<meta name="theme-color" content={siteConfig('BACKGROUND_DARK')} />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, minimum-scale=1.0" />
<meta name="robots" content="follow, index" />
<meta charSet="UTF-8" />
{BLOG.SEO_GOOGLE_SITE_VERIFICATION && (
{siteConfig('SEO_GOOGLE_SITE_VERIFICATION') && (
<meta
name="google-site-verification"
content={BLOG.SEO_GOOGLE_SITE_VERIFICATION}
content={siteConfig('SEO_GOOGLE_SITE_VERIFICATION')}
/>
)}
{BLOG.SEO_BAIDU_SITE_VERIFICATION && (<meta name="baidu-site-verification" content={BLOG.SEO_BAIDU_SITE_VERIFICATION} />)}
{siteConfig('SEO_BAIDU_SITE_VERIFICATION') && (<meta name="baidu-site-verification" content={siteConfig('SEO_BAIDU_SITE_VERIFICATION')} />)}
<meta name="keywords" content={keywords} />
<meta name="description" content={description} />
<meta property="og:locale" content={lang} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:url" content={url} />
<meta property="og:image" content={image} />
<meta property="og:site_name" content={BLOG.TITLE} />
<meta property="og:site_name" content={siteConfig('TITLE')} />
<meta property="og:type" content={type} />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:description" content={description} />
<meta name="twitter:title" content={title} />

{BLOG.COMMENT_WEBMENTION.ENABLE && (
{siteConfig('COMMENT_WEBMENTION_ENABLE') && (
<>
<link rel="webmention" href={`https://webmention.io/${BLOG.COMMENT_WEBMENTION.HOSTNAME}/webmention`} />
<link rel="pingback" href={`https://webmention.io/${BLOG.COMMENT_WEBMENTION.HOSTNAME}/xmlrpc`} />
<link rel="webmention" href={`https://webmention.io/${siteConfig('COMMENT_WEBMENTION_HOSTNAME')}/webmention`} />
<link rel="pingback" href={`https://webmention.io/${siteConfig('COMMENT_WEBMENTION_HOSTNAME')}/xmlrpc`} />
</>
)}

{BLOG.COMMENT_WEBMENTION.ENABLE && BLOG.COMMENT_WEBMENTION.AUTH !== '' && (
<link href={BLOG.COMMENT_WEBMENTION.AUTH} rel="me" />
{siteConfig('COMMENT_WEBMENTION_ENABLE') && siteConfig('COMMENT_WEBMENTION_AUTH') !== '' && (
<link href={siteConfig('COMMENT_WEBMENTION_AUTH')} rel="me" />
)}

{JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && <meta name="referrer" content="no-referrer-when-downgrade" />}
{JSON.parse(siteConfig('ANALYTICS_BUSUANZI_ENABLE')) && <meta name="referrer" content="no-referrer-when-downgrade" />}
{meta?.type === 'Post' && (
<>
<meta
property="article:published_time"
content={meta.publishDay}
/>
<meta property="article:author" content={BLOG.AUTHOR} />
<meta property="article:author" content={siteConfig('AUTHOR')} />
<meta property="article:section" content={category} />
<meta property="article:publisher" content={BLOG.FACEBOOK_PAGE} />
<meta property="article:publisher" content={siteConfig('FACEBOOK_PAGE')} />
</>
)}
{children}
Expand Down
Loading

0 comments on commit 1965fff

Please sign in to comment.