配置
使用 docs/config.json 配置站点信息与导航结构。
navbar:顶部导航nav:显示在社交链接旁边的主导航sidebar:侧边栏分组search:本地搜索选项markdown:Markdown 渲染选项locales:多语言配置
搜索
默认搜索使用内置 MiniSearch,无需额外依赖。
{
"search": {
"provider": "local"
}
}
代码块主题
你可以在 docs/config.json 中通过 markdown.codeTheme 配置代码块高亮主题。
使用单一主题:
{
"markdown": {
"codeTheme": "github-dark"
}
}
或分别配置亮色/暗色主题:
{
"markdown": {
"codeTheme": {
"light": "github-light",
"dark": "github-dark"
}
}
}
常见主题名(由 Astro 通过 Shiki 提供,具体可用性取决于 Astro/Shiki 版本):
github-lightgithub-darkone-dark-prodraculanordmaterial-theme-darkercatppuccin-lattecatppuccin-frappecatppuccin-macchiatocatppuccin-mocha
One Dark + Catppuccin 示例:
{
"markdown": {
"codeTheme": {
"light": "catppuccin-latte",
"dark": "one-dark-pro"
}
}
}
如果主题名在当前版本不可用,dev/build 会提示主题加载错误。
双语配置
推荐将中文文档放在 docs/zh/... 目录下,并在 locales 中配置 /zh/:
{
"locales": {
"/": {
"label": "English",
"lang": "en-US"
},
"/zh/": {
"label": "简体中文",
"lang": "zh-CN"
}
}
}
自定义首页
如果 config.json 里的 home 配置不够灵活,可以直接在 config.json 同目录放置 Astro 首页文件:
docs/
config.json
index.astro
zh/
index.astro
docs/index.astro会覆盖根路径/的首页。docs/zh/index.astro会覆盖/zh/的多语言首页。- 只要存在匹配的
index.astro,Stropress 就会优先使用它,而不是home或locales[locale].home。
这些文件会渲染在默认文档布局内部。你也可以在 Astro frontmatter 中导出一些可选元信息:
---
export const title = "自定义首页";
export const description = "使用 Astro 编写的首页";
export const sidebar = false;
---
<section>
<h1>自定义首页</h1>
</section>
全局样式覆盖
你可以在根目录增加 docs/index.css,用来全局覆盖默认主题样式。
这份文件会在内置主题 CSS 之后加载,因此适合用来重写 :root 变量,或者覆盖主题里的选择器。
:root {
--background-color: 250 247 240;
--foreground-color: 28 28 28;
--primary-color: 176 78 44;
}
.topbar {
backdrop-filter: blur(20px);
}