命令行
npx gem-book -h命令
# 启动开发服务器,每次请求都读取文档,修改文档后自动刷新页面
npx gem-book [dev] [docs-dir]
# 构建网站,所有页面预渲染到 dist/web
npx gem-book build [docs-dir]
# 构建网站并启动 dist/web 的服务,在本地预览
npx gem-book serve [docs-dir]文档目录默认为当前目录,它也是静态资源目录:文档中引用的图片等文件会和网站一起输出(Markdown 文件不会输出)。
选项
-t, --title <title>
指定网站标题,默认从 package.json 的 title 中读取或者使用当前工作目录名称。
--i18n
--port <port>
指定开发服务器的端口。
--config <path>
指定配置文件路径,默认为当前工作目录中的 gem-book.cli.json。
配置文件
其他设置都在配置文件 gem-book.cli.json 中,例如:
{
"$schema": "./schema.json",
"title": "GemBook",
"icon": "../../logo.png",
"i18n": true,
"homeMode": true,
"site": "https://book.gemjs.org",
"sourceBranch": "docs",
"ga": "G-PZYZ441YD3",
"port": 8090,
"global": {
"hello": "Hello World!"
},
"docsearch": {
"appId": "05KK61XW6A",
"apiKey": "b6738e2ef6d977e01ab3a325b91937e1",
"indexName": "book-gemjs"
}
}TIP
添加
"$schema": "https://unpkg.com/gem-book/schema.json"可以获得类型提示。
title
同 --title。
icon
图标路径(相对于当前工作目录)或者网址,显示在导航栏中,同时作为网站图标。
i18n
同 --i18n。
fallbackLanguage
没有启用国际化时文档的语言,启用时是默认语言,默认为 en。
homeMode
将文档根目录中的 README.md / index.md 以首页的布局显示,需要提供文档
ignored
忽略的文档或目录,相对于语言目录。没有 / 的规则匹配任意目录中的名称,* 匹配名称中的任意字符,** 匹配任意层级的目录,例如 ["drafts", "*.draft.md", "guide/**"]。node_modules 和 . 开头的名称总是被忽略。
versions
文档的旧版本,新的在前,例如 ["v2", "v1"],参考
displayRank
github
GitHub 或者 GitLab 仓库地址,显示在导航栏中,同时用于生成“编辑此页”的链接和最后更新时间,默认读取本地 Git 仓库的 origin。
sourceBranch
“编辑此页”链接使用的分支,默认为当前分支。
nav
导航栏中的链接,站外链接显示在右侧,标题为 twitter、discord 等的链接显示为图标:
{
"nav": [
{ "title": "Example", "link": "https://example.com" },
{ "title": "Twitter", "link": "https://twitter.com/xxx" }
]
}footer
页脚内容,Markdown 格式。
theme
内置主题的名称或者主题文件的路径,见
global
importMap
路径前缀映射,<gbp-raw>src 和 <gbp-api>
{
"importMap": {
"@mantou/tap-ui/": "node_modules/@mantou/tap-ui/src/"
}
}设置环境变量 GEM_BOOK_REPLACE 时,<gbp-example><gbp-import>https://esm.sh/@mantou/tap-ui/elements/button => node_modules/@mantou/tap-ui/src/elements/button.ts,适合开发 UI 库时使用:GEM_BOOK_REPLACE=true gem-book docs。
plugins
全站插件,模块的路径(相对于当前工作目录)或者包名,和网站一起打包,每个页面都会加载,参考
{
"plugins": ["docs/plugins/hello.ts"]
}docsearch
comment
ga
Google Analytics v4 的 ID,只在构建的网站中使用。
site
网站的地址,例如 https://book.gemjs.org,构建时生成 sitemap.xml,页面的 canonical 和 hreflang 链接使用完整的网址。
port
同 --port。
