@@ -53,7 +53,20 @@ function scanSubdirectories(directory) {
53
53
return subdirectories
54
54
}
55
55
56
+ /**
57
+ * @type {import('next').NextConfig }
58
+ */
59
+
56
60
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
+ } ,
57
70
images : {
58
71
// 图片压缩
59
72
formats : [ 'image/avif' , 'image/webp' ] ,
@@ -71,90 +84,87 @@ const nextConfig = {
71
84
} ,
72
85
73
86
// 默认将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
+ } ,
92
98
// 重写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
+ }
108
116
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
+ )
125
135
}
126
- )
127
- }
128
136
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
+ // 伪静态重写
145
140
{
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 [
149
150
{
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
+ ]
153
165
}
154
166
]
155
- }
156
- ]
157
- } ,
167
+ } ,
158
168
webpack : ( config , { dev, isServer } ) => {
159
169
// 动态主题:添加 resolve.alias 配置,将动态路径映射到实际路径
160
170
if ( ! isServer ) {
0 commit comments