Skip to content
Mintlify
Mintlify
自定义

字体

使用 Google Fonts 或自托管字体文件,为标题、正文和代码块自定义文档站点的排版样式。

可为整站,或分别为标题与正文字体设置自定义字体。你可以使用 Google Fonts、本地字体文件,或外部托管的字体。默认字体因主题而异。

docs.json 中使用 fonts 属性 配置字体。

当你在 docs.json 中指定字体族名称时,Mintlify 会自动加载 Google Fonts

docs.json
"fonts": {
  "family": "Inter"
}

要使用本地字体,请将字体文件放在项目目录中,并在 docs.json 配置中进行引用。

将字体文件添加到项目

例如,创建一个 fonts 目录并添加字体文件:

your-project/
├── fonts/
│   ├── InterDisplay-Regular.woff2
│   └── InterDisplay-Bold.woff2
├── docs.json
└── ...

在 docs.json 中配置字体

从项目根目录使用相对路径引用本地字体:

docs.json
{
  "fonts": {
    "family": "InterDisplay",
    "source": "/fonts/InterDisplay-Regular.woff2",
    "format": "woff2",
    "weight": 400
  }
}

在你的 docs.json 中分别为标题和正文配置本地字体:

docs.json
{
  "fonts": {
    "heading": {
      "family": "InterDisplay",
      "source": "/fonts/InterDisplay-Bold.woff2",
      "format": "woff2",
      "weight": 700
    },
    "body": {
      "family": "InterDisplay",
      "source": "/fonts/InterDisplay-Regular.woff2",
      "format": "woff2",
      "weight": 400
    }
  }
}

docs.json 中通过引用字体源的 URL 来使用外部托管的字体:

docs.json
{
  "fonts": {
    "family": "Hubot Sans",
    "source": "https://mintlify-assets.b-cdn.net/fonts/Hubot-Sans.woff2",
    "format": "woff2",
    "weight": 400
  }
}
fontsobject

文档站点的字体配置。

Show Fonts
familystringrequired

字体系列名称,例如 “Inter” 或 “Playfair Display”。

weightnumber

字重,例如 400 或 700。可变字体支持更精确的字重,如 550。

sourcestring (uri)

字体来源的 URL,例如 https://mintlify-assets.b-cdn.net/fonts/Hubot-Sans.woff2,或本地字体文件路径,例如 /assets/fonts/InterDisplay.woff2。当你指定 Google 字体的 family 名称时会自动加载 Google Fonts,因此无需提供 source 的 URL。

format'woff' | 'woff2'

字体文件格式。使用 source 字段时为必填。

headingobject

覆盖标题专用的字体设置。

Show Heading
familystringrequired

标题的字体系列名称。

weightnumber

标题字重。

sourcestring (uri)

字体来源的 URL,例如 https://mintlify-assets.b-cdn.net/fonts/Hubot-Sans.woff2,或标题使用的本地字体文件路径。当你指定 Google 字体的 family 名称时会自动加载 Google Fonts,因此无需提供 source 的 URL。

format'woff' | 'woff2'

标题的字体文件格式。使用 source 字段时为必填。

bodyobject

覆盖正文专用的字体设置。

Show Body
familystringrequired

正文的字体系列名称。

weightnumber

正文字重。

sourcestring (uri)

字体来源的 URL,例如 https://mintlify-assets.b-cdn.net/fonts/Hubot-Sans.woff2,或正文使用的本地字体文件路径。当你指定 Google 字体的 family 名称时会自动加载 Google Fonts,因此无需提供 source 的 URL。

format'woff' | 'woff2'

正文的字体文件格式。使用 source 字段时为必填。

Was this page helpful?Suggest editsRaise issue