菜单系统
Kecare 提供统一的菜单配置方式,用于生成侧边导航栏。
创建菜单
菜单文件存放在 .kecare/menus/ 目录,命名格式为 <名称>.menu.source.ts:
// .kecare/menus/kecare-docs.menu.source.ts
import type { NavItem } from "kecare";
export const navItems: NavItem[] = [
{
text: "分组名称",
level: 1,
items: [
{ text: "菜单项", link: "./文章路径.md", level: 2 },
],
},
{
text: "分组名称2",
level: 1,
items: [
{ text: "菜单项2", link: "./文章路径2.md", level: 2 },
],
}
];
文件名前缀(如
kecare-docs)是文章中引用的menu值。
在文章中启用
在 Front Matter 中添加 menu 字段:
---
title: 快速开始
menu: kecare-docs
---
menu 值对应菜单文件名前缀:kecare-docs → kecare-docs.menu.source.ts
NavItem 结构
type NavItem =
| { text: string; link: string; level: number; desc?: string; icon?: string } // 叶子节点
| { text: string; items: NavItem[]; level: number }; // 分组节点
- 叶子节点:可点击跳转,
link为文章路径(如./快速开始) - 分组节点:仅作分类,包含
items子数组