forked from CuteLeaf/Firefly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastro.config.mjs
More file actions
276 lines (269 loc) · 7.89 KB
/
astro.config.mjs
File metadata and controls
276 lines (269 loc) · 7.89 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
import sitemap from "@astrojs/sitemap";
import svelte from "@astrojs/svelte";
import tailwindcss from "@tailwindcss/vite";
import { pluginCollapsibleSections } from "@expressive-code/plugin-collapsible-sections";
import { pluginLineNumbers } from "@expressive-code/plugin-line-numbers";
import swup from "@swup/astro";
import { defineConfig } from "astro/config";
import expressiveCode from "astro-expressive-code";
import icon from "astro-icon";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeComponents from "rehype-components"; /* Render the custom directive content */
import rehypeKatex from "rehype-katex";
import katex from "katex";
import "katex/dist/contrib/mhchem.mjs"; // 加载 mhchem 扩展
import rehypeSlug from "rehype-slug";
import remarkDirective from "remark-directive"; /* Handle directives */
import remarkMath from "remark-math";
import rehypeCallouts from "rehype-callouts";
import remarkSectionize from "remark-sectionize";
import { expressiveCodeConfig, siteConfig } from "./src/config";
import { i18n } from "./src/i18n/translation";
import I18nKey from "./src/i18n/i18nKey";
import { pluginLanguageBadge } from "expressive-code-language-badge"; /* Language Badge */
import { pluginCollapsible } from "expressive-code-collapsible"; /* Collapsible */
import { GithubCardComponent } from "./src/plugins/rehype-component-github-card.mjs";
import { rehypeMermaid } from "./src/plugins/rehype-mermaid.mjs";
import { parseDirectiveNode } from "./src/plugins/remark-directive-rehype.js";
import { remarkExcerpt } from "./src/plugins/remark-excerpt.js";
import { remarkMermaid } from "./src/plugins/remark-mermaid.js";
import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs";
import mdx from "@astrojs/mdx";
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 { remarkImageGrid } from "./src/plugins/remark-image-grid.js";
// https://astro.build/config
export default defineConfig({
site: siteConfig.site_url,
base: "/",
trailingSlash: "always",
// 图像优化配置
image: {
// 全局响应式布局
layout: "constrained",
},
experimental: {
// Rust 编译器以提升构建性能(实验性),部分平台可能会导致构建失败,可以根据需要启用或禁用
rustCompiler: false,
// 队列渲染以优化性能(实验性)
queuedRendering: { enabled: true },
},
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 && event.state.url && event.state.url.includes("#");
},
}),
icon({
include: {
"material-symbols": ["*"],
"fa7-brands": ["*"],
"fa7-regular": ["*"],
"fa7-solid": ["*"],
"simple-icons": ["*"],
mdi: ["*"],
},
}),
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:
"'JetBrains Mono Variable', 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 === "/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;
}
return true;
},
}),
mdx(),
],
markdown: {
remarkPlugins: [
remarkMath,
remarkReadingTime,
remarkImageGrid,
remarkExcerpt,
remarkDirective,
remarkSectionize,
parseDirectiveNode,
remarkMermaid,
],
rehypePlugins: [
[rehypeKatex, { katex }],
[rehypeCallouts, { theme: siteConfig.rehypeCallouts.theme }],
rehypeSlug,
rehypeMermaid,
rehypeFigure,
[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.rehypeCallouts.theme}`,
},
},
build: {
minify: "esbuild",
esbuildOptions: {
minify: true,
// 移除 console.log 和 debugger
drop: ["console", "debugger"],
},
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,
},
},
});