Skip to content

Commit 77a8e99

Browse files
committed
2 parents 9584386 + be048bb commit 77a8e99

26 files changed

+348
-268
lines changed

.env.local

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
2-
NEXT_PUBLIC_VERSION=4.5.4
2+
NEXT_PUBLIC_VERSION=4.6.0
33

44

55
# 可在此添加环境变量,去掉最左边的(# )注释即可

blog.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ const BLOG = {
545545
process.env.ENABLE_CACHE ||
546546
process.env.npm_lifecycle_event === 'build' ||
547547
process.env.npm_lifecycle_event === 'export', // 在打包过程中默认开启缓存,开发或运行时开启此功能意义不大。
548-
isProd: process.env.VERCEL_ENV === 'production', // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
548+
isProd: process.env.VERCEL_ENV === 'production' || process.env.EXPORT, // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
549549
BUNDLE_ANALYZER: process.env.ANALYZE === 'true' || false, // 是否展示编译依赖内容与大小
550550
VERSION: process.env.NEXT_PUBLIC_VERSION // 版本号
551551
}

components/ExternalPlugins.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import LA51 from './LA51'
55
import TianLiGPT from './TianliGPT'
66
import WebWhiz from './Webwhiz'
77

8-
import { CUSTOM_EXTERNAL_CSS, CUSTOM_EXTERNAL_JS } from '@/blog.config'
98
import { convertInnerUrl } from '@/lib/notion/convertInnerUrl'
109
import { isBrowser, loadExternalResource } from '@/lib/utils'
1110
import { useRouter } from 'next/router'
@@ -44,8 +43,6 @@ const ExternalPlugin = props => {
4443
const CHATBASE_ID = siteConfig('CHATBASE_ID')
4544
const COMMENT_DAO_VOICE_ID = siteConfig('COMMENT_DAO_VOICE_ID')
4645
const AD_WWADS_ID = siteConfig('AD_WWADS_ID')
47-
// const COMMENT_TWIKOO_ENV_ID = siteConfig('COMMENT_TWIKOO_ENV_ID')
48-
// const COMMENT_TWIKOO_CDN_URL = siteConfig('COMMENT_TWIKOO_CDN_URL')
4946
const COMMENT_ARTALK_SERVER = siteConfig('COMMENT_ARTALK_SERVER')
5047
const COMMENT_ARTALK_JS = siteConfig('COMMENT_ARTALK_JS')
5148
const COMMENT_TIDIO_ID = siteConfig('COMMENT_TIDIO_ID')
@@ -64,6 +61,8 @@ const ExternalPlugin = props => {
6461
const IMG_SHADOW = siteConfig('IMG_SHADOW')
6562
const ANIMATE_CSS_URL = siteConfig('ANIMATE_CSS_URL')
6663
const MOUSE_FOLLOW = siteConfig('MOUSE_FOLLOW')
64+
const CUSTOM_EXTERNAL_CSS = siteConfig('CUSTOM_EXTERNAL_CSS')
65+
const CUSTOM_EXTERNAL_JS = siteConfig('CUSTOM_EXTERNAL_JS')
6766

6867
// 自定义样式css和js引入
6968
if (isBrowser) {

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const convertVal = val => {
122122
}
123123

124124
// 配置值前可能有污染的空格
125-
if (!val.indexOf('[') > 0 || val.indexOf('{')) {
125+
if (val.indexOf('[') < 0 && val.indexOf('{') < 0) {
126126
return val
127127
}
128128

lib/notion/getPageProperties.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
192192
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
193193
if (
194194
!properties?.href?.endsWith('.html') &&
195-
!properties?.href?.startsWith('http')
195+
!properties?.href?.startsWith('http') &&
196+
properties?.href !== '' &&
197+
properties?.href !== '#' &&
198+
properties?.href !== '/'
196199
) {
197200
properties.href += '.html'
198201
}

lib/utils/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function isUrl(str) {
9797
// 检查是否外链
9898
export function checkStartWithHttp(str) {
9999
// 检查字符串是否包含http
100-
if (str?.includes('http:') || str?.includes('https:')) {
100+
if (str?.indexOf('http:') === 0 || str?.indexOf('https:') === 0) {
101101
// 如果包含,找到http的位置
102102
return str?.indexOf('http') > -1
103103
} else {

next.config.js

+86-76
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,20 @@ function scanSubdirectories(directory) {
5353
return subdirectories
5454
}
5555

56+
/**
57+
* @type {import('next').NextConfig}
58+
*/
59+
5660
const nextConfig = {
61+
output: process.env.EXPORT ? 'export' : undefined,
62+
// 多语言, 在export时禁用
63+
i18n: process.env.EXPORT
64+
? undefined
65+
: {
66+
defaultLocale: BLOG.LANG.slice(0, 2),
67+
// 支持的所有多语言,按需填写即可
68+
locales
69+
},
5770
images: {
5871
// 图片压缩
5972
formats: ['image/avif', 'image/webp'],
@@ -71,90 +84,87 @@ const nextConfig = {
7184
},
7285

7386
// 默认将feed重定向至 /public/rss/feed.xml
74-
async redirects() {
75-
return [
76-
{
77-
source: '/feed',
78-
destination: '/rss/feed.xml',
79-
permanent: true
80-
}
81-
]
82-
},
83-
// 多语言, 在export时禁用
84-
i18n:
85-
process.env.npm_lifecycle_event === 'export'
86-
? undefined
87-
: {
88-
defaultLocale: BLOG.LANG.slice(0, 2),
89-
// 支持的所有多语言,按需填写即可
90-
locales
91-
},
87+
redirects: process.env.EXPORT
88+
? undefined
89+
: async () => {
90+
return [
91+
{
92+
source: '/feed',
93+
destination: '/rss/feed.xml',
94+
permanent: true
95+
}
96+
]
97+
},
9298
// 重写url
93-
async rewrites() {
94-
// 处理多语言重定向
95-
const langsRewrites = []
96-
if (BLOG.NOTION_PAGE_ID.indexOf(',') > 0) {
97-
const siteIds = BLOG.NOTION_PAGE_ID.split(',')
98-
const langs = []
99-
for (let index = 0; index < siteIds.length; index++) {
100-
const siteId = siteIds[index]
101-
const prefix = extractLangPrefix(siteId)
102-
// 如果包含前缀 例如 zh , en 等
103-
if (prefix) {
104-
langs.push(prefix)
105-
}
106-
console.log('[Locales]', siteId)
107-
}
99+
rewrites: process.env.EXPORT
100+
? undefined
101+
: async () => {
102+
// 处理多语言重定向
103+
const langsRewrites = []
104+
if (BLOG.NOTION_PAGE_ID.indexOf(',') > 0) {
105+
const siteIds = BLOG.NOTION_PAGE_ID.split(',')
106+
const langs = []
107+
for (let index = 0; index < siteIds.length; index++) {
108+
const siteId = siteIds[index]
109+
const prefix = extractLangPrefix(siteId)
110+
// 如果包含前缀 例如 zh , en 等
111+
if (prefix) {
112+
langs.push(prefix)
113+
}
114+
console.log('[Locales]', siteId)
115+
}
108116

109-
// 映射多语言
110-
// 示例: source: '/:locale(zh|en)/:path*' ; :locale() 会将语言放入重写后的 `?locale=` 中。
111-
langsRewrites.push(
112-
{
113-
source: `/:locale(${langs.join('|')})/:path*`,
114-
destination: '/:path*'
115-
},
116-
// 匹配没有路径的情况,例如 [domain]/zh 或 [domain]/en
117-
{
118-
source: `/:locale(${langs.join('|')})`,
119-
destination: '/'
120-
},
121-
// 匹配没有路径的情况,例如 [domain]/zh/ 或 [domain]/en/
122-
{
123-
source: `/:locale(${langs.join('|')})/`,
124-
destination: '/'
117+
// 映射多语言
118+
// 示例: source: '/:locale(zh|en)/:path*' ; :locale() 会将语言放入重写后的 `?locale=` 中。
119+
langsRewrites.push(
120+
{
121+
source: `/:locale(${langs.join('|')})/:path*`,
122+
destination: '/:path*'
123+
},
124+
// 匹配没有路径的情况,例如 [domain]/zh 或 [domain]/en
125+
{
126+
source: `/:locale(${langs.join('|')})`,
127+
destination: '/'
128+
},
129+
// 匹配没有路径的情况,例如 [domain]/zh/ 或 [domain]/en/
130+
{
131+
source: `/:locale(${langs.join('|')})/`,
132+
destination: '/'
133+
}
134+
)
125135
}
126-
)
127-
}
128136

129-
return [
130-
...langsRewrites,
131-
// 伪静态重写
132-
{
133-
source: '/:path*.html',
134-
destination: '/:path*'
135-
}
136-
]
137-
},
138-
async headers() {
139-
return [
140-
{
141-
source: '/:path*{/}?',
142-
headers: [
143-
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
144-
{ key: 'Access-Control-Allow-Origin', value: '*' },
137+
return [
138+
...langsRewrites,
139+
// 伪静态重写
145140
{
146-
key: 'Access-Control-Allow-Methods',
147-
value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT'
148-
},
141+
source: '/:path*.html',
142+
destination: '/:path*'
143+
}
144+
]
145+
},
146+
headers: process.env.EXPORT
147+
? undefined
148+
: async () => {
149+
return [
149150
{
150-
key: 'Access-Control-Allow-Headers',
151-
value:
152-
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
151+
source: '/:path*{/}?',
152+
headers: [
153+
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
154+
{ key: 'Access-Control-Allow-Origin', value: '*' },
155+
{
156+
key: 'Access-Control-Allow-Methods',
157+
value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT'
158+
},
159+
{
160+
key: 'Access-Control-Allow-Headers',
161+
value:
162+
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
163+
}
164+
]
153165
}
154166
]
155-
}
156-
]
157-
},
167+
},
158168
webpack: (config, { dev, isServer }) => {
159169
// 动态主题:添加 resolve.alias 配置,将动态路径映射到实际路径
160170
if (!isServer) {

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notion-next",
3-
"version": "4.5.4",
3+
"version": "4.6.0",
44
"homepage": "https://github.com/tangly1024/NotionNext.git",
55
"license": "MIT",
66
"repository": {
@@ -17,7 +17,7 @@
1717
"build": "next build",
1818
"start": "next start",
1919
"post-build": "next-sitemap --config next-sitemap.config.js",
20-
"export": "next build && next-sitemap --config next-sitemap.config.js && next export",
20+
"export": "cross-env EXPORT=true next build && next-sitemap --config next-sitemap.config.js",
2121
"bundle-report": "cross-env ANALYZE=true next build",
2222
"build-all-in-dev": "cross-env VERCEL_ENV=production next build"
2323
},
@@ -30,7 +30,7 @@
3030
"js-md5": "^0.7.3",
3131
"lodash.throttle": "^4.1.1",
3232
"memory-cache": "^0.2.0",
33-
"next": "13.3.1",
33+
"next": "14.2.4",
3434
"notion-client": "6.15.6",
3535
"notion-utils": "6.15.6",
3636
"react": "^18.2.0",

pages/[prefix]/[slug]/[...suffix].js

+14-10
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ export async function getStaticProps({
8383
props.post = null
8484
return {
8585
props,
86-
revalidate: siteConfig(
87-
'REVALIDATE_SECOND',
88-
BLOG.NEXT_REVALIDATE_SECOND,
89-
props.NOTION_CONFIG
90-
)
86+
revalidate: process.env.EXPORT
87+
? undefined
88+
: siteConfig(
89+
'NEXT_REVALIDATE_SECOND',
90+
BLOG.NEXT_REVALIDATE_SECOND,
91+
props.NOTION_CONFIG
92+
)
9193
}
9294
}
9395

@@ -122,11 +124,13 @@ export async function getStaticProps({
122124
delete props.allPages
123125
return {
124126
props,
125-
revalidate: siteConfig(
126-
'NEXT_REVALIDATE_SECOND',
127-
BLOG.NEXT_REVALIDATE_SECOND,
128-
props.NOTION_CONFIG
129-
)
127+
revalidate: process.env.EXPORT
128+
? undefined
129+
: siteConfig(
130+
'NEXT_REVALIDATE_SECOND',
131+
BLOG.NEXT_REVALIDATE_SECOND,
132+
props.NOTION_CONFIG
133+
)
130134
}
131135
}
132136

pages/[prefix]/[slug]/index.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ export async function getStaticProps({ params: { prefix, slug }, locale }) {
7272
props.post = null
7373
return {
7474
props,
75-
revalidate: siteConfig(
76-
'REVALIDATE_SECOND',
77-
BLOG.NEXT_REVALIDATE_SECOND,
78-
props.NOTION_CONFIG
79-
)
75+
revalidate: process.env.EXPORT
76+
? undefined
77+
: siteConfig(
78+
'NEXT_REVALIDATE_SECOND',
79+
BLOG.NEXT_REVALIDATE_SECOND,
80+
props.NOTION_CONFIG
81+
)
8082
}
8183
}
8284

@@ -111,11 +113,13 @@ export async function getStaticProps({ params: { prefix, slug }, locale }) {
111113
delete props.allPages
112114
return {
113115
props,
114-
revalidate: siteConfig(
115-
'NEXT_REVALIDATE_SECOND',
116-
BLOG.NEXT_REVALIDATE_SECOND,
117-
props.NOTION_CONFIG
118-
)
116+
revalidate: process.env.EXPORT
117+
? undefined
118+
: siteConfig(
119+
'NEXT_REVALIDATE_SECOND',
120+
BLOG.NEXT_REVALIDATE_SECOND,
121+
props.NOTION_CONFIG
122+
)
119123
}
120124
}
121125

pages/[prefix]/index.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ export async function getStaticProps({ params: { prefix }, locale }) {
151151
props.post = null
152152
return {
153153
props,
154-
revalidate: siteConfig(
155-
'REVALIDATE_SECOND',
156-
BLOG.NEXT_REVALIDATE_SECOND,
157-
props.NOTION_CONFIG
158-
)
154+
revalidate: process.env.EXPORT
155+
? undefined
156+
: siteConfig(
157+
'NEXT_REVALIDATE_SECOND',
158+
BLOG.NEXT_REVALIDATE_SECOND,
159+
props.NOTION_CONFIG
160+
)
159161
}
160162
}
161163

@@ -191,11 +193,13 @@ export async function getStaticProps({ params: { prefix }, locale }) {
191193
delete props.allPages
192194
return {
193195
props,
194-
revalidate: siteConfig(
195-
'NEXT_REVALIDATE_SECOND',
196-
BLOG.NEXT_REVALIDATE_SECOND,
197-
props.NOTION_CONFIG
198-
)
196+
revalidate: process.env.EXPORT
197+
? undefined
198+
: siteConfig(
199+
'NEXT_REVALIDATE_SECOND',
200+
BLOG.NEXT_REVALIDATE_SECOND,
201+
props.NOTION_CONFIG
202+
)
199203
}
200204
}
201205

0 commit comments

Comments
 (0)