Skip to content
🎉 欢迎加入主题交流群,查看二维码
QQ交流群 QQ交流群 681489336
微信群微信交流群

如扫码无法加入,可加好友备注“主题”

文章配置

介绍常用的一些 官方默认主题 提供的能力:

outline

  • Type: number | [number, number] | 'deep' | false
  • Default: 2

设置文章自动生成的目录,和 config.themeConfig.outline 表现一样,文章里单独设置的优先级更高

md
---
# 取二三级标题生成目录
outline: [2,3]
---

cleanUrls

需要服务器支持

要使用 VitePress 提供干净的 URL,需要服务器端支持。

详见:generating-clean-url

默认情况下,VitePress 解析以 .html 结尾的 URL 的入站链接。但是,某些用户可能更喜欢不带 .html 扩展名的“干净 URL” - 例如, example.com/path 而不是 example.com/path.html

可以先通过修改 VitePress 配置在购建时支持将路由处理成无 .html 后缀

ts
import { defineConfig } from 'vitepress'

export default defineConfig({
  // 详见:https://vitepress.dev/reference/site-config#cleanurls
  cleanUrls: true,
})

紧接着是修改服务端的配置,下面是常用的平台配置

sh
location / {
   try_files $uri $uri/ $uri.html /404.html;
}
json
{
  "cleanUrls": true
}

如果不配置 VitePress cleanUrls 又想没有后缀的路由能够正常访问?

只需要配置服务端配置即可

🎉 欢迎扫码加入主题交流群

QQ交流群 QQ交流群 681489336
微信群微信交流群

如扫码无法加入,可加好友备注“主题”