@@ -19,18 +19,18 @@ export enum Chapters {
1919 // xrobot 主章节
2020 xrobot = "/xrobot/" ,
2121 // guide
22- xrobot_guide = "/xrobot/guide" ,
23- xrobot_guide_mp = "/xrobot/guide/mini-program" ,
22+ xrobot_guide = "/xrobot/guide/ " ,
23+ xrobot_guide_mp = "/xrobot/guide/mini-program/ " ,
2424 xrobot_guide_device = "/xrobot/guide/device/" ,
25- xrobot_guide_console = "/xrobot/guide/console" ,
26- xrobot_guide_net_config = "/xrobot/guide/net-config" ,
25+ xrobot_guide_console = "/xrobot/guide/console/ " ,
26+ xrobot_guide_net_config = "/xrobot/guide/net-config/ " ,
2727 // api
2828 xrobot_api = "/xrobot/api/" ,
2929 xrobot_api_server = "/xrobot/api/server/" ,
3030 xrobot_api_client = "/xrobot/api/client/" ,
3131 // platform
32- xrobot_platform = "/xrobot/platform" ,
33- xrobot_platform_esp32 = "/xrobot/platform/esp32" ,
32+ xrobot_platform = "/xrobot/platform/ " ,
33+ xrobot_platform_esp32 = "/xrobot/platform/esp32/ " ,
3434 // faq
3535 xrobot_faq = "/xrobot/faq/" ,
3636}
@@ -42,6 +42,11 @@ export function isChapter<T extends Record<string, string>>(
4242 return Object . values ( Chapters ) . includes ( link as Chapters ) ;
4343}
4444
45+ export function isSubChapter ( link : string ) {
46+ const t = link . split ( "/" ) . filter ( ( p ) => p !== "" ) ;
47+ return t . length > 1 && isChapter ( link ) ;
48+ }
49+
4550// // 给 ChapterItem 的 link 字段追加当前章节的 link 前缀
4651// // 通过是否包含子items来判断
4752// export function apply_prefix2(item: ChapterItem, prefix: Chapters) {
@@ -264,3 +269,23 @@ export const ChapterItems: Record<Chapters, ChapterItem[]> = {
264269 // faq
265270 [ Chapters . xrobot_faq ] : [ gobackItem ( Chapters . xrobot ) , ...items_xrobot_faq ] ,
266271} ;
272+
273+ // 获得章节items, 所有level~maxLevel层级的章节
274+ export function getChapterItems (
275+ level ?: 1 | 2 | 3 | 4 | 5 ,
276+ maxLevel ?: 1 | 2 | 3 | 4 | 5
277+ ) {
278+ const _level = level ?? 1 ;
279+ const _maxLevel = maxLevel ?? 6 ;
280+ // 满足条件的ChapterItems的key
281+ const chap = Object . values ( Chapters ) . filter ( ( ch ) => {
282+ const len = ch . split ( "/" ) . filter ( ( p ) => p !== "" ) . length ;
283+ return _level <= len && len <= _maxLevel ;
284+ } ) ;
285+
286+ let res = { } ;
287+ chap . forEach ( ( ch ) => {
288+ res [ ch ] = ChapterItems [ ch ] ;
289+ } ) ;
290+ return res ;
291+ }
0 commit comments