useCategory() 读取 app.config 的 docs.categories,把分类标题解析为当前语言的文案。useNavigation 据此把页面分组。
推荐:在 app.config 中声明
键为顶层栏目目录的 slug(去掉数字前缀),值为分类列表,列表顺序即侧栏顺序:
app/app.config.ts
export default defineAppConfig({
docs: {
categories: {
guide: [
{ id: 'basics', title: { 'zh-CN': '基础', 'en': 'Basics' }, icon: 'i-lucide-settings' },
{ id: 'shipping', title: { 'zh-CN': '发布', 'en': 'Shipping' }, icon: 'i-lucide-rocket' }
]
}
}
})
页面在 frontmatter 中用 category 归入分类:
content/docs/2.guide/9.deployment.md
---
title: 部署
category: shipping
---
完整说明见 导航与分类。
签名
function useCategory(): {
categories: ComputedRef<Record<string, Category[]>>
}
interface Category {
id: string
title: string
icon: string
}
返回值
| 名称 | 类型 | 说明 |
|---|---|---|
categories | ComputedRef<Record<string, Category[]>> | 键为栏目 slug,值为该栏目的分类列表,title 已解析为当前语言 |
覆盖
在项目中创建同名文件即可覆盖,返回结构须保持 { categories }:
app/composables/useCategory.ts
export function useCategory() {
const { t } = useMovkI18n()
const categories = computed(() => ({
guide: [
{ id: 'basics', title: t('docs.overview'), icon: 'i-lucide-settings' }
]
}))
return {
categories
}
}
覆盖后 docs.categories 不再生效。
更新日志
No recent changes