scalar-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseScalar Docs Configuration Skill — scalar.config.json
Scalar Docs配置技能 — scalar.config.json
Reference for writing and updating , the central configuration file for Scalar Docs. Use this when creating, editing, or validating Docs configuration for any project.
scalar.config.json本指南是用于编写和更新的参考文档,该文件是Scalar Docs的核心配置文件。适用于创建、编辑或验证任意项目的Docs配置场景。
scalar.config.jsonOverview
概述
- File: (or
scalar.config.json)scalar.config.json5 - Location: Repository root by default; path can be overridden in Scalar Dashboard
- Schema: — enables autocomplete in VS Code/Cursor when
https://registry.scalar.com/@scalar/schemas/configis truejson.schemaDownload.enable - Version: Use for the latest format
"scalar": "2.0.0"
- 文件:(或
scalar.config.json)scalar.config.json5 - 位置:默认位于仓库根目录;可在Scalar Dashboard中覆盖路径设置
- Schema:— 当
https://registry.scalar.com/@scalar/schemas/config设为true时,可在VS Code/Cursor中启用自动补全功能json.schemaDownload.enable - 版本:最新格式请使用
"scalar": "2.0.0"
Quick Start
快速开始
Create a minimal config:
bash
npx @scalar/cli project initMinimal structure:
json
{
"$schema": "https://registry.scalar.com/@scalar/schemas/config",
"scalar": "2.0.0",
"info": {
"title": "My Documentation",
"description": "The best documentation you've read today"
},
"navigation": {
"routes": {
"/": {
"title": "Introduction",
"type": "page",
"filepath": "docs/introduction.md"
}
}
}
}Validate config:
npx @scalar/cli project check-config创建最简配置:
bash
npx @scalar/cli project init最简结构:
json
{
"$schema": "https://registry.scalar.com/@scalar/schemas/config",
"scalar": "2.0.0",
"info": {
"title": "My Documentation",
"description": "The best documentation you've read today"
},
"navigation": {
"routes": {
"/": {
"title": "Introduction",
"type": "page",
"filepath": "docs/introduction.md"
}
}
}
}验证配置:
npx @scalar/cli project check-configRoot Properties
根属性
| Property | Type | Description |
|---|---|---|
| | JSON Schema URL for editor autocomplete and validation |
| | Configuration version. Use |
| | Project metadata (title, description) |
| | Navigation structure (header, routes, sidebar, tabs) |
| | Site-level settings (domain, theme, head, logo, routing) |
| | Relative path to assets folder from config root |
| 属性 | 类型 | 描述 |
|---|---|---|
| | 用于编辑器自动补全和验证的JSON Schema URL |
| | 配置版本,请使用 |
| | 项目元数据(标题、描述) |
| | 导航结构(头部、路由、侧边栏、标签页) |
| | 站点级设置(域名、主题、头部、Logo、路由) |
| | 相对于配置根目录的资源文件夹路径 |
info
info
Project metadata displayed across the site:
json
{
"info": {
"title": "My Documentation",
"description": "Comprehensive guides for our API"
}
}站点中展示的项目元数据:
json
{
"info": {
"title": "My Documentation",
"description": "Comprehensive guides for our API"
}
}navigation
navigation
All navigation is in . Each route key is the URL path; the value is a config object.
navigation.routes所有导航配置都在中。每个路由键为URL路径,对应的值为配置对象。
navigation.routesnavigation.header
navigation.header
Links in the top bar. Use to push items before it left and after it right.
type: "spacer"json
"header": [
{ "type": "link", "title": "Home", "to": "/" },
{ "type": "spacer" },
{ "type": "link", "title": "Log in", "to": "https://dashboard.example.com/login", "newTab": true },
{ "type": "link", "title": "Register", "style": "button", "icon": "phosphor/regular/user-plus", "to": "https://...", "newTab": true }
]Properties: , ( | ), , ( | ), ,
titletype"link""spacer"tostyle"button""link"iconnewTab顶部导航栏中的链接。使用可将其左侧的项左移、右侧的项右移。
type: "spacer"json
"header": [
{ "type": "link", "title": "Home", "to": "/" },
{ "type": "spacer" },
{ "type": "link", "title": "Log in", "to": "https://dashboard.example.com/login", "newTab": true },
{ "type": "link", "title": "Register", "style": "button", "icon": "phosphor/regular/user-plus", "to": "https://...", "newTab": true }
]属性:、( | )、、( | )、、
titletype"link""spacer"tostyle"button""link"iconnewTabnavigation.sidebar
navigation.sidebar
Links at the bottom of the sidebar:
json
"sidebar": [
{ "title": "Log in", "url": "https://...", "style": "button", "newTab": true }
]侧边栏底部的链接:
json
"sidebar": [
{ "title": "Log in", "url": "https://...", "style": "button", "newTab": true }
]navigation.tabs
navigation.tabs
Tabs for quick access to sections:
json
"tabs": [
{ "title": "API", "path": "/api", "icon": "phosphor/regular/plug" }
]用于快速访问各板块的标签页:
json
"tabs": [
{ "title": "API", "path": "/api", "icon": "phosphor/regular/plug" }
]Route Types
路由类型
Page (type: "page"
)
type: "page"页面(type: "page"
)
type: "page"Markdown/MDX content from a file:
json
"/getting-started": {
"type": "page",
"title": "Getting Started",
"filepath": "docs/getting-started.md",
"description": "Optional SEO description",
"icon": "phosphor/regular/rocket",
"showInSidebar": true,
"layout": { "toc": true, "sidebar": true }
}Layout: (default ), (default ).
toctruesidebartrueHidden pages: Set to hide a page from the sidebar while keeping it accessible via its direct URL.
showInSidebar: false来自文件的Markdown/MDX内容:
json
"/getting-started": {
"type": "page",
"title": "Getting Started",
"filepath": "docs/getting-started.md",
"description": "Optional SEO description",
"icon": "phosphor/regular/rocket",
"showInSidebar": true,
"layout": { "toc": true, "sidebar": true }
}布局:(默认)、(默认)。
toctruesidebartrue隐藏页面:设置可将页面从侧边栏隐藏,但仍可通过直接URL访问。
showInSidebar: falseOpenAPI (type: "openapi"
)
type: "openapi"OpenAPI(type: "openapi"
)
type: "openapi"API reference from file, Registry, or URL:
File:
json
"/api": {
"type": "openapi",
"title": "My API",
"filepath": "docs/api-reference/openapi.yaml",
"icon": "phosphor/regular/plug"
}Registry:
json
"/api": {
"type": "openapi",
"title": "My API",
"namespace": "my-organization",
"slug": "your-api"
}URL:
json
"/api": {
"type": "openapi",
"title": "My API",
"url": "https://example.com/openapi.json"
}Display modes: (default), , .
folderflatnestedAPI Reference options (authentication, theme, etc.) go in a object — same options as the API Reference configuration.
config来自文件、Registry或URL的API参考:
文件:
json
"/api": {
"type": "openapi",
"title": "My API",
"filepath": "docs/api-reference/openapi.yaml",
"icon": "phosphor/regular/plug"
}Registry:
json
"/api": {
"type": "openapi",
"title": "My API",
"namespace": "my-organization",
"slug": "your-api"
}URL:
json
"/api": {
"type": "openapi",
"title": "My API",
"url": "https://example.com/openapi.json"
}展示模式:(默认)、、。
folderflatnestedAPI参考选项(认证、主题等)需放在对象中——与API Reference配置的选项一致。
configGroup (type: "group"
)
type: "group"分组(type: "group"
)
type: "group"Collapsible section with children:
json
"/products": {
"type": "group",
"title": "Products",
"mode": "flat",
"icon": "phosphor/regular/package",
"children": {
"/docs": { "type": "page", "title": "Documentation", "filepath": "docs/documentation.md" },
"/api": { "type": "openapi", "title": "API Reference", "filepath": "openapi.yaml" }
}
}Modes: , , (default).
flatnestedfolder包含子项的可折叠板块:
json
"/products": {
"type": "group",
"title": "Products",
"mode": "flat",
"icon": "phosphor/regular/package",
"children": {
"/docs": { "type": "page", "title": "Documentation", "filepath": "docs/documentation.md" },
"/api": { "type": "openapi", "title": "API Reference", "filepath": "openapi.yaml" }
}
}模式:、、(默认)。
flatnestedfolderLink (type: "link"
)
type: "link"链接(type: "link"
)
type: "link"External URL:
json
"/github": {
"type": "link",
"title": "GitHub",
"url": "https://github.com/org/repo",
"icon": "phosphor/regular/github-logo"
}外部URL:
json
"/github": {
"type": "link",
"title": "GitHub",
"url": "https://github.com/org/repo",
"icon": "phosphor/regular/github-logo"
}siteConfig
siteConfig
branding
品牌设置
Logo — single URL or per mode:
json
"logo": "https://example.com/logo.svg"
// or
"logo": {
"darkMode": "https://example.com/logo-dark.svg",
"lightMode": "https://example.com/logo-light.svg"
}Theme — one of: , , , , , , , , , , ,
defaultalternatemoonpurplesolarizedbluePlanetdeepSpacesaturnkeplermarslaserwavenonejson
"theme": "purple"Logo — 单个URL或分模式设置:
json
"logo": "https://example.com/logo.svg"
// 或
"logo": {
"darkMode": "https://example.com/logo-dark.svg",
"lightMode": "https://example.com/logo-light.svg"
}主题 — 可选值:, , , , , , , , , , ,
defaultalternatemoonpurplesolarizedbluePlanetdeepSpacesaturnkeplermarslaserwavenonejson
"theme": "purple"domain
域名
Subdomain (free):
https://<subdomain>.apidocumentation.comjson
"subdomain": "your-docs"Custom domain (Pro):
https://docs.example.comjson
"customDomain": "docs.example.com"Subpath — for multiple projects on same domain:
json
"subpath": "/guides"子域名(免费):
https://<subdomain>.apidocumentation.comjson
"subdomain": "your-docs"自定义域名(Pro版):
https://docs.example.comjson
"customDomain": "docs.example.com"子路径 — 同一域名下部署多个项目:
json
"subpath": "/guides"layout
布局
json
"layout": {
"toc": true,
"header": true
}json
"layout": {
"toc": true,
"header": true
}head
头部
Inject scripts, styles, meta tags, and links:
json
"head": {
"title": "My Documentation",
"meta": [
{ "name": "description", "content": "API documentation" },
{ "property": "og:image", "content": "https://example.com/og.png" }
],
"styles": [{ "path": "docs/assets/custom.css", "tagPosition": "head" }],
"scripts": [{ "path": "docs/assets/analytics.js", "tagPosition": "bodyClose" }],
"links": [{ "rel": "icon", "href": "/favicon.png" }]
}For and : path relative to config root. For (favicon): root-relative ().
scriptsstyleslinks/favicon.pngtagPosition"head""bodyOpen""bodyClose"注入脚本、样式、元标签和链接:
json
"head": {
"title": "My Documentation",
"meta": [
{ "name": "description", "content": "API documentation" },
{ "property": "og:image", "content": "https://example.com/og.png" }
],
"styles": [{ "path": "docs/assets/custom.css", "tagPosition": "head" }],
"scripts": [{ "path": "docs/assets/analytics.js", "tagPosition": "bodyClose" }],
"links": [{ "rel": "icon", "href": "/favicon.png" }]
}对于和:路径为相对于配置根目录的路径。对于(如favicon):使用根相对路径()。
scriptsstyleslinks/favicon.pngtagPosition"head""bodyOpen""bodyClose"footer
页脚
json
"footer": {
"filepath": "docs/footer.html",
"belowSidebar": true
}json
"footer": {
"filepath": "docs/footer.html",
"belowSidebar": true
}routing
路由
Redirects:
json
"routing": {
"redirects": [
{ "from": "/old-path", "to": "/new-path" },
{ "from": "/old-path/:wildcard", "to": "/new-path" },
{ "from": "/old-path/:pathMatch(.*)*", "to": "/new-path" }
]
}Path patterns:
json
"routing": {
"guidePathPattern": "/docs/:slug",
"referencePathPattern": "/api/:slug"
}重定向:
json
"routing": {
"redirects": [
{ "from": "/old-path", "to": "/new-path" },
{ "from": "/old-path/:wildcard", "to": "/new-path" },
{ "from": "/old-path/:pathMatch(.*)*", "to": "/new-path" }
]
}路径模式:
json
"routing": {
"guidePathPattern": "/docs/:slug",
"referencePathPattern": "/api/:slug"
}assetsDir
assetsDir
Relative path to assets folder. Assets are served from site root.
json
"assetsDir": "docs/assets"In Markdown: or .
In : use full path relative to config root for scripts/styles; root-relative for links.
siteConfig.head资源文件夹的相对路径。资源将从站点根目录提供服务。
json
"assetsDir": "docs/assets"在Markdown中: 或 。
在中:脚本/样式使用相对于配置根目录的完整路径;链接使用根相对路径。
siteConfig.headMigration from Docs 1.0
从Docs 1.0迁移
Docs 1.0 used and arrays. Docs 2.0 uses .
guidesreferencesnavigation.routesUpgrade:
bash
npx @scalar/cli project upgradeCheck result:
bash
npx @scalar/cli project previewDocs 1.0使用和数组。Docs 2.0使用。
guidesreferencesnavigation.routes升级命令:
bash
npx @scalar/cli project upgrade检查结果:
bash
npx @scalar/cli project previewCLI Commands
CLI命令
| Command | Description |
|---|---|
| Create scalar.config.json |
| Validate config |
| Local preview (port 7971) |
| Publish from local files |
| Publish from linked GitHub repo |
| Migrate from Docs 1.0 |
| 命令 | 描述 |
|---|---|
| 创建scalar.config.json |
| 验证配置 |
| 本地预览(端口7971) |
| 从本地文件发布 |
| 从关联的GitHub仓库发布 |
| 从Docs 1.0迁移 |
Common Patterns
常见模式
Multi-project on same domain: Same or , different per repo.
customDomainsubdomainsubpathMDX: Use extension in ; same structure as Markdown pages.
.mdxfilepathHide TOC on a page: on that route.
"layout": { "toc": false }API Reference auth: Add under the openapi route with (same options as API Reference config).
configauthenticationCustom domain DNS: CNAME host → (DNS-only, no proxy).
docsdns.scalar.com同一域名下多项目: 相同的或,每个仓库使用不同的。
customDomainsubdomainsubpathMDX: 在中使用扩展名;结构与Markdown页面一致。
filepath.mdx隐藏页面目录: 在对应路由中设置。
"layout": { "toc": false }API参考认证: 在openapi路由下添加包含的对象(与API Reference配置选项一致)。
authenticationconfig自定义域名DNS: 将CNAME主机指向(仅DNS,无需代理)。
docsdns.scalar.com