-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathastro.config.mjs
More file actions
335 lines (324 loc) · 10.2 KB
/
Copy pathastro.config.mjs
File metadata and controls
335 lines (324 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import { setMaxListeners } from "node:events";
import { unified } from "@astrojs/markdown-remark";
import sitemap from "@astrojs/sitemap";
import svelte from "@astrojs/svelte";
import { pluginCollapsibleSections } from "@expressive-code/plugin-collapsible-sections";
import { pluginLineNumbers } from "@expressive-code/plugin-line-numbers";
import swup from "@swup/astro";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "astro/config";
import expressiveCode from "astro-expressive-code";
import icon from "astro-icon";
import katex from "katex";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeComponents from "rehype-components"; /* Render the custom directive content */
import rehypeKatex from "rehype-katex";
import "katex/dist/contrib/mhchem.mjs"; // 加载 mhchem 扩展
import cloudflare from "@astrojs/cloudflare";
import mdx from "@astrojs/mdx";
import { pluginCollapsible } from "expressive-code-collapsible"; /* Collapsible */
import { pluginLanguageBadge } from "expressive-code-language-badge"; /* Language Badge */
import rehypeCallouts from "rehype-callouts";
import rehypeSlug from "rehype-slug";
import remarkAdmonitionToBlockquoteCallout from "remark-admonition-to-blockquote-callout";
import remarkDirective from "remark-directive"; /* Handle directives */
import remarkMath from "remark-math";
import remarkSectionize from "remark-sectionize";
import { expressiveCodeConfig, fontConfig, fontsList, mermaidConfig, plantumlConfig, siteConfig } from "./src/config";
import { collectUsedFontCssVars } from "./src/utils/fontHelper";
import I18nKey from "./src/i18n/i18nKey";
import { i18n } from "./src/i18n/translation";
import { fontProviders } from "astro/config";
import { GithubCardComponent } from "./src/plugins/rehype-component-github-card.mjs";
import rehypeEmailProtection from "./src/plugins/rehype-email-protection.mjs";
import rehypeExternalLinks from "./src/plugins/rehype-external-links.mjs";
import rehypeFigure from "./src/plugins/rehype-figure.mjs";
import rehypeImageReferrerPolicy from "./src/plugins/rehype-image-referrerpolicy.mjs";
import { rehypeDiagramPanZoom } from "./src/plugins/rehype-diagram-panzoom.mjs";
import { rehypeMermaid } from "./src/plugins/rehype-mermaid.mjs";
import { rehypePlantuml } from "./src/plugins/rehype-plantuml.mjs";
import { parseDirectiveNode } from "./src/plugins/remark-directive-rehype.js";
import { remarkExcerpt } from "./src/plugins/remark-excerpt.js";
import { remarkImageGrid } from "./src/plugins/remark-image-grid.js";
import { remarkMermaid } from "./src/plugins/remark-mermaid.js";
import { remarkPlantuml } from "./src/plugins/remark-plantuml.js";
import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs";
if (process.env.NODE_ENV === "development") {
setMaxListeners(20);
}
const adapter = process.env.CF_WORKERS
? cloudflare({
prerenderEnvironment: "node",
})
: undefined;
// https://astro.build/config
export default defineConfig({
site: siteConfig.site_url,
base: "/",
trailingSlash: "always",
// 字体配置 - 只加载实际使用的字体,跳过未引用的以加快构建
fonts: (() => {
// 禁用字体功能时直接返回空数组,跳过 Astro Font API 集成
if (!fontConfig.enable) return [];
const used = collectUsedFontCssVars(fontConfig);
return fontsList
.filter((f) => used.has(f.cssVariable))
.map((f) => {
let provider;
switch (f.provider) {
case "google": provider = fontProviders.google(); break;
case "fontsource": provider = fontProviders.fontsource(); break;
case "local": provider = fontProviders.local(); break;
case "bunny": provider = fontProviders.bunny(); break;
case "fontshare": provider = fontProviders.fontshare(); break;
case "npm": provider = fontProviders.npm(); break;
default: provider = f.provider;
}
return { ...f, provider };
});
})(),
adapter,
// 图像优化配置
image: {
// 全局响应式布局
layout: "constrained",
},
integrations: [
swup({
theme: false,
animationClass: "transition-swup-", // see https://swup.js.org/options/#animationselector
// the default value `transition-` cause transition delay
// when the Tailwind class `transition-all` is used
containers: [
"#banner-overlay-container",
"#banner-dim-container",
"#swup-container",
"#left-sidebar-dynamic",
"#right-sidebar-dynamic",
"#floating-toc-wrapper",
],
smoothScrolling: false,
cache: true,
preload: true,
accessibility: true,
updateHead: true,
updateBodyClass: false,
globalInstance: true,
// 滚动相关配置优化
resolveUrl: (url) => url,
animateHistoryBrowsing: false,
skipPopStateHandling: (event) => {
// 跳过锚点链接的处理,让浏览器原生处理
return event.state?.url?.includes("#");
},
}),
icon({
include: {
"material-symbols": ["*"],
"fa7-brands": ["*"],
"fa7-regular": ["*"],
"fa7-solid": ["*"],
"simple-icons": ["*"],
mdi: ["*"],
mingcute: ["*"],
},
}),
expressiveCode({
themes: [expressiveCodeConfig.darkTheme, expressiveCodeConfig.lightTheme],
useDarkModeMediaQuery: false,
themeCssSelector: (theme) => `[data-theme='${theme.name}']`,
plugins: [
// pluginLanguageBadge 配置 - 从expressiveCodeConfig读取设置
...(expressiveCodeConfig.pluginLanguageBadge?.enable === true
? [pluginLanguageBadge()]
: []),
pluginCollapsibleSections(),
pluginLineNumbers(),
// pluginCollapsible 配置 - 从expressiveCodeConfig读取设置,使用i18n文本
...(expressiveCodeConfig.pluginCollapsible?.enable === true
? [
pluginCollapsible({
lineThreshold:
expressiveCodeConfig.pluginCollapsible.lineThreshold || 15,
previewLines:
expressiveCodeConfig.pluginCollapsible.previewLines || 8,
defaultCollapsed:
expressiveCodeConfig.pluginCollapsible.defaultCollapsed ??
true,
expandButtonText: i18n(I18nKey.codeCollapsibleShowMore),
collapseButtonText: i18n(I18nKey.codeCollapsibleShowLess),
expandedAnnouncement: i18n(I18nKey.codeCollapsibleExpanded),
collapsedAnnouncement: i18n(I18nKey.codeCollapsibleCollapsed),
}),
]
: []),
],
defaultProps: {
wrap: false,
overridesByLang: {
shellsession: {
showLineNumbers: false,
},
},
},
styleOverrides: {
borderRadius: "0.75rem",
codeFontSize: "0.875rem",
codeFontFamily:
"var(--font-jetbrains-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace",
codeLineHeight: "1.5rem",
frames: {},
textMarkers: {
delHue: 0,
insHue: 180,
markHue: 250,
},
languageBadge: {
fontSize: "0.75rem",
fontWeight: "bold",
borderRadius: "0.25rem",
opacity: "1",
borderWidth: "0px",
borderColor: "transparent",
},
},
frames: {
showCopyToClipboardButton: true,
},
}),
svelte(),
sitemap({
filter: (page) => {
// 根据页面开关配置过滤sitemap
const url = new URL(page);
const pathname = url.pathname;
if (pathname === "/dynamic/" && !siteConfig.pages.dynamic) {
return false;
}
if (pathname === "/friends/" && !siteConfig.pages.friends) {
return false;
}
if (pathname === "/sponsor/" && !siteConfig.pages.sponsor) {
return false;
}
if (pathname === "/guestbook/" && !siteConfig.pages.guestbook) {
return false;
}
if (pathname === "/bangumi/" && !siteConfig.pages.bangumi) {
return false;
}
if (pathname === "/gallery/" && !siteConfig.pages.gallery) {
return false;
}
if (pathname === "/anime/" && !siteConfig.pages.anime) {
return false;
}
return true;
},
}),
mdx(),
],
markdown: {
processor: unified({
remarkPlugins: [
...(siteConfig.post.rehypeCallouts.enablePythonMarkdownAdmonitions !== false
? [remarkAdmonitionToBlockquoteCallout]
: []),
remarkMath,
remarkReadingTime,
remarkImageGrid,
remarkExcerpt,
remarkDirective,
remarkSectionize,
parseDirectiveNode,
remarkMermaid,
[remarkPlantuml, plantumlConfig],
],
rehypePlugins: [
[rehypeKatex, { katex }],
[rehypeCallouts, { theme: siteConfig.post.rehypeCallouts.theme }],
rehypeSlug,
[rehypeMermaid, mermaidConfig],
rehypePlantuml,
rehypeDiagramPanZoom,
rehypeFigure,
[
rehypeImageReferrerPolicy,
{ domains: siteConfig.imageOptimization?.noReferrerDomains || [] },
],
[rehypeExternalLinks, { siteUrl: siteConfig.site_url }],
[rehypeEmailProtection, { method: "base64" }], // 邮箱保护插件,支持 'base64' 或 'rot13'
[
rehypeComponents,
{
components: {
github: GithubCardComponent,
},
},
],
[
rehypeAutolinkHeadings,
{
behavior: "append",
properties: {
className: ["anchor"],
},
content: {
type: "element",
tagName: "span",
properties: {
className: ["anchor-icon"],
"data-pagefind-ignore": true,
},
children: [
{
type: "text",
value: "#",
},
],
},
},
],
],
}),
},
vite: {
plugins: [tailwindcss()],
server: {
watch: {
ignored: ["**/package/**", "**/Firefly-docs/**"],
},
},
resolve: {
alias: {
"@rehype-callouts-theme": `rehype-callouts/theme/${siteConfig.post.rehypeCallouts.theme}`,
},
},
build: {
minify: "esbuild",
esbuildOptions: {
minify: true,
// 删除 debugger 语句;console.log / console.debug 无副作用,未使用返回值时会被 dead code elimination 移除,
// console.warn / console.error 保留,确保生产环境出错时仍有日志可查
drop: ["debugger"],
pure: ["console.log", "console.debug"],
},
rollupOptions: {
onwarn(warning, warn) {
// temporarily suppress this warning
if (
warning.message.includes("is dynamically imported by") &&
warning.message.includes("but also statically imported by")
) {
return;
}
warn(warning);
},
},
// CSS 优化
cssCodeSplit: true,
cssMinify: "esbuild",
assetsInlineLimit: 4096,
},
},
});