跳转至

配置参考

本页面记录 docsforge.yml 中可用的每个选项。自定义站点时,请将其作为完整参考。


顶层设置

site_name

文档站点的标题。显示在页眉、浏览器标签页和社交卡片中。

site_name: My Documentation
类型默认值必填
string

site_url

站点托管的规范 URL。用于社交卡片、RSS 订阅源和绝对链接生成。

site_url: https://example.com/docs/
类型默认值必填
stringnull

尾部斜杠

始终包含尾部斜杠以保持一致:

site_url: https://example.com/docs/  # 推荐
site_url: https://example.com/docs   # 避免

site_author

作者姓名。用于元数据和 RSS 订阅源。

site_author: Jane Doe
类型默认值必填
stringnull

site_description

站点简短描述。用于元标签和社交卡片。

site_description: Documentation for the Example Platform
类型默认值必填
stringnull

页脚显示的版权信息。

copyright: Copyright © 2025 Example Inc.
类型默认值必填
stringnull

repo_url

源代码仓库 URL。在页眉中添加指向仓库的编辑图标。

repo_url: https://github.com/example/docs
类型默认值必填
stringnull

repo_name

仓库链接的显示名称。默认为 repo_url 的最后一段路径。

repo_name: example/docs
类型默认值必填
string自动

edit_uri

“编辑此页”链接的路径后缀。与 repo_url 组合成完整编辑 URL。

edit_uri: edit/main/docs/
类型默认值必填
stringnull

strict

设置为 true 时,警告会被视为错误,构建失败。

strict: true
类型默认值必填
booleanfalse

dev_addr

开发服务器地址。

dev_addr: 127.0.0.1:8000
类型默认值必填
string127.0.0.1:8000

use_directory_urls

设置为 true(默认)时,页面构建为 page/index.html 而非 page.html。这会生成更简洁的 URL(/page/ 而非 /page.html)。

use_directory_urls: true
类型默认值必填
booleantrue

docs_dir

包含 Markdown 源文件的目录。

docs_dir: docs
类型默认值必填
stringdocs

site_dir

构建站点输出的目录。

site_dir: site
类型默认值必填
stringsite

extra_css

额外包含的 CSS 文件。路径相对于 docs_dir

extra_css:
  - stylesheets/custom.css
类型默认值必填
list[]

extra_javascript

额外包含的 JavaScript 文件。路径相对于 docs_dir

extra_javascript:
  - javascripts/analytics.js
类型默认值必填
list[]

不要包含已内置的资源

不要在此处包含 KaTeX、Mermaid 或 Material Icons。它们已内置。


主题设置

主题设置位于 theme: 块下,与 DocsForge Material 相同。

theme:
  name: material
  palette:
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: indigo
      accent: indigo
      toggle:
        icon: material/brightness-7
        name: Switch to dark mode
    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      primary: indigo
      accent: indigo
      toggle:
        icon: material/brightness-4
        name: Switch to light mode
  features:
    - navigation.tabs
    - navigation.sections
    - navigation.top
    - search.suggest
    - search.highlight
    - content.code.copy
  logo: assets/logo.svg
  favicon: assets/favicon.svg
  icon:
    repo: fontawesome/brands/github

theme.name

要使用的主题。DocsForge 内置 Material,因此通常是 material

theme:
  name: material
类型默认值必填
stringmaterial

theme.palette

配色方案配置。支持浅色/深色模式切换。

theme:
  palette:
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: indigo
      accent: indigo
      toggle:
        icon: material/brightness-7
        name: Switch to dark mode
    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      primary: indigo
      accent: indigo
      toggle:
        icon: material/brightness-4
        name: Switch to light mode
属性类型描述
mediastring自动切换的 CSS 媒体查询
schemestring配色方案:defaultslate
primarystring主色:redpinkpurpledeep-purpleindigobluelight-bluecyantealgreenlight-greenlimeyellowamberorangedeep-orangebrowngreyblue-greyblackwhite
accentstring强调色(选项与 primary 相同)
toggleobject切换按钮配置
toggle.iconstring图标标识符
toggle.namestring工具提示文本

theme.features

要启用的导航和 UI 功能。

theme:
  features:
    - navigation.tabs
    - navigation.sections
    - navigation.expand
    - navigation.path
    - navigation.top
    - search.suggest
    - search.highlight
    - content.tabs.link
    - content.code.copy
    - content.action.edit
功能描述
navigation.tabs顶层导航标签页
navigation.sections侧边栏中的章节页面
navigation.expand默认展开所有章节
navigation.path面包屑导航
navigation.top返回顶部按钮
navigation.footer上一页/下一页页脚链接
search.suggest页眉中的搜索建议
search.highlight结果中高亮搜索词
search.share分享搜索查询链接
content.tabs.link跨页面链接内容标签页
content.code.copy代码块上的复制按钮
content.code.annotate代码注释
content.action.edit编辑页面按钮
content.action.view查看源代码按钮
announce.dismiss可关闭的公告栏

theme.icon

各种 UI 元素的图标配置。

theme:
  icon:
    repo: fontawesome/brands/github
    logo: material/library
属性类型描述
repostring仓库链接图标
logostring徽标区域使用的图标
admonitionobject自定义提示框图标

站点徽标路径(相对于 docs_dir)。

theme:
  logo: assets/logo.svg
类型默认值必填
stringnull

theme.favicon

Favicon 路径(相对于 docs_dir)。

theme:
  favicon: assets/favicon.svg
类型默认值必填
stringnull

theme.language

站点语言,用于国际化。

theme:
  language: en
类型默认值必填
stringen

theme.direction

文本方向。

theme:
  direction: ltr
类型默认值选项
stringltrltrrtl

theme.custom_dir

自定义模板和覆盖的目录(相对于 docs_dir)。

theme:
  custom_dir: overrides
类型默认值必填
stringnull

插件设置

DocsForge 有许多内置插件。大多数无需配置。仅在需要自定义行为时才添加设置。

plugins

plugins:
  search:
    lang: en
  tags:
    tags_file: tags.md
  blog:
    blog_dir: blog
    blog_toc: true
选项类型默认值描述
langstringen搜索词干提取语言
separatorstring[\s\-]+单词分隔符正则
pipelinelist[trimmer, stopWordFilter, stemmer]处理管道
jieba_dictstringnull自定义 jieba 字典路径
jieba_dict_userstringnull自定义 jieba 用户字典路径

tags 插件

选项类型默认值描述
tags_filestringtags.md标签索引页面
tags_extra_fileslist[]额外标签文件
tags_hierarchybooleanfalse启用标签层级

blog 插件

选项类型默认值描述
blog_dirstringblog博客文章目录
blog_tocbooleanfalse显示目录
post_date_formatstringlong日期格式
post_excerptstringoptional摘要行为
post_readtimebooleantrue显示阅读时间
post_url_formatstring{date}/{slug}URL 模式
archive_date_formatstringYYYY归档格式
archive_url_formatstringarchive/{date}归档 URL
categories_url_formatstringcategory/{slug}分类 URL
pagination_url_formatstringpage/{page}分页 URL
authors_filestring.authors.yml作者文件

minify 插件

minify 插件始终启用,没有可配置选项。它会压缩 HTML 页面以及任何 extra_css / extra_javascript 文件。

privacy 插件

选项类型默认值描述
enabledbooleantrue启用插件
concurrencyintegerCPU count - 1下载并发数
cache_dirstring.cache/plugin/privacy本地缓存目录
assets_fetchbooleantrue从网络获取外部资源
assets_fetch_dirstringassets/externalsite_dir 内的存储目录
assets_includelist[]始终获取的外部 URL 通配模式
assets_excludelist[]跳过获取的外部 URL 通配模式
assets_expr_mapdict{}在 CSS/JS 中查找资源的额外正则
links_attr_mapdict{}添加到外部链接的额外属性
links_noopenerbooleantrue为外部链接添加 noopener

info 插件

选项类型默认值描述
enabledbooleantrue启用插件
enabled_on_servebooleanfalse服务时显示 info 输出

meta 插件

选项类型默认值描述
meta_filestring.meta.yml元数据文件
enabledbooleantrue启用插件

Markdown 扩展

DocsForge 默认启用大多数常见扩展。仅在需要自定义行为时才配置。

markdown_extensions

markdown_extensions:
  - toc:
      permalink: true
      title: On this page
      toc_depth: 3
扩展内置描述
admonition标注框(!!! note
pymdownx.details可折叠详情(??? question
pymdownx.superfences支持自定义围栏的代码块
pymdownx.highlight代码语法高亮
pymdownx.inlinehilite行内代码高亮
pymdownx.snippets内容包含(--8<--
pymdownx.tabbed标签页内容(=== "Tab 1"
pymdownx.tasklist任务列表(- [ ]
pymdownx.emoji表情和图标(:material-check:
pymdownx.arithmatex数学渲染($...$$$...$$
pymdownx.keys键盘按键(++ctrl+c++
pymdownx.mark高亮文本(==text==
pymdownx.critic批评标记
pymdownx.caret上标(^text^
pymdownx.tilde下标(~text~
tablesMarkdown 表格
toc目录
metaYAML 前置元数据
def_list定义列表
footnotes脚注([^1]
attr_list属性列表({.class}
md_in_htmlHTML 内的 Markdown
smarty智能引号和破折号
sane_lists严格列表嵌套
wikilinksWiki 风格链接

Extra 设置

extra: 部分保存可在模板和 Markdown 中通过 {{ extra.key }} 访问的自定义变量。

extra.social

页脚中的社交链接。

extra:
  social:
    - icon: fontawesome/brands/github
      link: https://github.com/example
      name: Example on GitHub
    - icon: fontawesome/brands/twitter
      link: https://twitter.com/example
      name: Example on Twitter

extra.alternate

多语言站点的语言替代链接。

extra:
  alternate:
    - name: English
      link: /
      lang: en
    - name: Deutsch
      link: /de/
      lang: de

extra.tags

标签配置。

extra:
  tags:
    file: tags.md
    icons:
      - name: "New"
        icon: material/star

extra.annotate

代码注释设置。

extra:
  annotate:
    json: [.s2]

extra.scope

Google Analytics / Plausible 作用域。

extra:
  scope:
    analytics: true
    feedback: true

导航

显式导航结构。如果省略,页面会自动从 docs_dir 发现。

nav:
  - Home: index.md
  - Getting Started:
    - Installation: getting-started/installation.md
    - Quick Start: getting-started/quick-start.md
  - Reference:
    - API: reference/api.md
    - CLI: reference/cli.md
  - Blog: blog/
语法描述
Page Title: path.md自定义标题的单个页面
Section:嵌套章节
Directory/自动发现目录中的页面
!include path包含另一个导航文件

验证设置

validation

链接、锚点和导航验证。

validation:
  nav:
    omitted_files: warn
    not_found: warn
  links:
    absolute_links: warn
    unrecognized_links: warn
    anchors: warn

validation.nav

选项类型默认值描述
omitted_filesstringinfo不在 nav 中的文件
not_foundstringwarn导航链接指向缺失页面
absolute_linksstringinfo绝对导航链接
选项类型默认值描述
absolute_linksstringinfo绝对 Markdown 链接
unrecognized_linksstringinfo看起来不像内部页面的链接
not_foundstringwarnMarkdown 链接指向缺失页面
anchorsstringinfo指向缺失锚点的链接

取值:warninfoignore


完整示例

# 站点元数据
site_name: Example Documentation
site_url: https://docs.example.com/
site_author: Example Team
site_description: Complete documentation for the Example platform
copyright: Copyright &copy; 2025 Example Inc.

# 仓库
repo_url: https://github.com/example/docs
repo_name: example/docs
edit_uri: edit/main/docs/

# 目录
docs_dir: docs
site_dir: site
use_directory_urls: true
strict: false

# 主题
theme:
  name: material
  palette:
    - media: "(prefers-color-scheme: light)"
      scheme: default
      primary: indigo
      accent: indigo
      toggle:
        icon: material/brightness-7
        name: Switch to dark mode
    - media: "(prefers-color-scheme: dark)"
      scheme: slate
      primary: indigo
      accent: indigo
      toggle:
        icon: material/brightness-4
        name: Switch to light mode
  features:
    - navigation.tabs
    - navigation.sections
    - navigation.expand
    - navigation.top
    - search.suggest
    - search.highlight
    - content.tabs.link
    - content.code.copy
    - content.action.edit
  logo: assets/logo.svg
  favicon: assets/favicon.svg
  icon:
    repo: fontawesome/brands/github
  language: en

# 自定义资源
extra_css:
  - stylesheets/custom.css

extra_javascript:
  - javascripts/analytics.js

# 插件
plugins:
  search:
    lang: en
  tags:
    tags_file: tags.md
  blog:
    blog_dir: blog
    blog_toc: true

# 额外变量
extra:
  social:
    - icon: fontawesome/brands/github
      link: https://github.com/example
    - icon: fontawesome/brands/twitter
      link: https://twitter.com/example

# 导航
nav:
  - Home: index.md
  - Getting Started:
    - Installation: getting-started/installation.md
    - Configuration: getting-started/configuration.md
  - Reference:
    - API: reference/api.md
    - CLI: reference/cli.md
  - Blog: blog/

# 验证
validation:
  nav:
    omitted_files: warn
    not_found: warn
  links:
    absolute_links: warn
    unrecognized_links: warn
    anchors: warn