-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathastro.config.mjs
More file actions
213 lines (200 loc) · 6.06 KB
/
astro.config.mjs
File metadata and controls
213 lines (200 loc) · 6.06 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
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import tailwindcss from "@tailwindcss/vite";
import sitemap from "@astrojs/sitemap";
import rehypeExternalLinks from "rehype-external-links";
import { loadSidebarConfig } from "./src/utils/sidebarLoader";
import { sidebarCategory } from "./src/utils/sign";
import {
remarkRemoveMdLinks,
remarkRemovePlainLanguageCode,
remarkRemoveRepeatHeader,
addPrefixImageLink,
setLinkReferrer,
} from "./src/utils/frontmatter.mjs";
import fs from "node:fs/promises";
import path from "node:path";
import { writeLlmsTxt } from "./src/utils/llmsTxtGenerator.ts";
// 加载所有 sidebar 配置
const zhDocsSidebar = loadSidebarConfig("root", "docs");
const zhAiSidebar = loadSidebarConfig("root", "ai");
const zhHimarketSidebar = loadSidebarConfig("root", "himarket");
const zhHiclawSidebar = loadSidebarConfig("root", "hiclaw");
const zhDeveloperSidebar = loadSidebarConfig("root", "developer");
// Custom integration to copy markdown files
const copyMarkdownIntegration = () => ({
name: "copy-markdown",
hooks: {
"astro:build:done": async ({ dir }) => {
const srcDir = path.join(process.cwd(), "src/content/docs");
const destDir = path.join(dir.pathname, "overview"); // dir is a URL object
// Function to recursively copy files
const copyDir = async (src, dest) => {
await fs.mkdir(dest, { recursive: true });
const entries = await fs.readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
await copyDir(srcPath, destPath);
} else if (
entry.isFile() &&
(entry.name.endsWith(".md") || entry.name.endsWith(".mdx"))
) {
await fs.copyFile(srcPath, destPath);
}
}
};
try {
console.log(`Copying markdown files from ${srcDir} to ${destDir}...`);
await copyDir(srcDir, destDir);
console.log("Markdown files copied successfully.");
} catch (err) {
console.error("Error copying markdown files:", err);
}
},
},
});
// Custom integration to generate llms.txt
const llmsTxtIntegration = () => ({
name: "llms-txt",
hooks: {
"astro:build:done": async ({ dir }) => {
const contentDir = path.join(process.cwd(), "src/content");
const outputDir = dir.pathname; // dir is a URL object
try {
await writeLlmsTxt(outputDir, contentDir);
} catch (err) {
console.error("Error generating llms.txt:", err);
}
},
},
});
// https://astro.build/config
export default defineConfig({
site: "https://higress.ai",
devToolbar: {
enabled: false,
},
integrations: [
sitemap({
i18n: {
defaultLocale: "zh-CN",
locales: {
"zh-CN": "zh-CN",
en: "en",
},
},
}),
copyMarkdownIntegration(),
llmsTxtIntegration(),
starlight({
title: "Higress",
expressiveCode: {
// 使用高对比度的亮色主题,与网站强制亮色模式保持一致
themes: ["github-light"],
// 网站只有亮色模式,禁用暗色模式切换
useStarlightDarkModeSwitch: false,
// 使用 Starlight 的 UI 主题颜色
useStarlightUiThemeColors: true,
},
customCss: ["./src/styles/global.css", "./src/styles/fonts.css"],
defaultLocale: "root",
locales: {
root: {
label: "简体中文",
lang: "zh-CN",
},
en: {
label: "English",
lang: "en",
},
},
// 使用中文 docs 作为默认 sidebar(只是为了让 Starlight 不报错)
sidebar: [
{
label: sidebarCategory.latest,
items: zhDocsSidebar,
},
{
label: sidebarCategory.ai,
items: zhAiSidebar,
},
{
label: sidebarCategory.himarket,
items: zhHimarketSidebar,
},
{
label: sidebarCategory.hiclaw,
items: zhHiclawSidebar,
},
{
label: sidebarCategory.developer,
items: zhDeveloperSidebar,
},
],
head: [
{
tag: "link",
attrs: {
rel: "icon",
href: "https://img.alicdn.com/imgextra/i4/O1CN01AViQMJ1J2lY4OPRgv_!!6000000000971-2-tps-376-375.png",
},
},
{
tag: "script",
attrs: {
src: "https://www.googletagmanager.com/gtag/js?id=G-34NDHLSRQX",
async: true,
},
},
{
tag: "script",
attrs: {
src: "/scripts.js",
},
},
],
components: {
PageTitle: "./src/components/starlight/PageTitle.astro",
// Head: "./src/components/starlight/Head.astro",
Header: "./src/components/starlight/Header.astro",
Footer: "./src/components/starlight/Footer.astro",
Sidebar: "./src/components/starlight/Sidebar.astro",
PageFrame: "./src/components/starlight/PageFrame.astro",
TwoColumnContent: "./src/components/starlight/TwoColumnContent.astro",
Search: "./src/components/starlight/Search.astro",
},
}),
],
vite: {
plugins: [tailwindcss()],
},
markdown: {
rehypePlugins: [
// 在这里添加 rehype-external-links 插件配置
[
rehypeExternalLinks,
{
target: "_blank",
},
],
],
remarkPlugins: [
remarkRemoveMdLinks,
remarkRemovePlainLanguageCode,
remarkRemoveRepeatHeader,
addPrefixImageLink,
setLinkReferrer,
],
},
redirects: {
"/en-us/": "/en/",
"/en/ai/": "/en/docs/ai/quick-start",
"/docs/": "/docs/latest/overview/what-is-higress/",
"/docs/latest/dev/CustomResourceDefinition/":
"/docs/latest/dev/customresourcedefinition/",
"/en-us/docs/latest/dev/CustomResourceDefinition/":
"/en/docs/latest/dev/customresourcedefinition/",
},
});