@@ -16,27 +16,32 @@ export type ChapterItem = {
1616export enum Chapters {
1717 // xrobot 主章节
1818 xrobot = "/xrobot/" ,
19-
19+ // guide
2020 xrobot_guide = "/xrobot/guide" ,
2121 xrobot_guide_mp = "/xrobot/guide/mini-program" ,
2222 xrobot_guide_device = "/xrobot/device/" ,
23-
23+ // api
2424 xrobot_api = "/xrobot/api/" ,
2525 xrobot_api_server = "/xrobot/api/server" ,
2626 xrobot_api_client = "/xrobot/api/client" ,
27-
27+ // faq
2828 xrobot_faq = "/xrobot/faq/" ,
2929}
3030
31- // 判断一个link 字符串是否是章节link
32- export function isChapter < T extends Record < string , string > > (
33- link : string
34- ) : link is T [ keyof T ] {
35- return Object . values ( Chapters ) . includes ( link as Chapters ) ;
36- }
31+ // // 给 ChapterItem 的 link 字段追加当前章节的 link 前缀
32+ // // 通过是否包含子items来判断
33+ // export function apply_prefix2(item: ChapterItem, prefix: Chapters) {
34+ // if (item.items) {
35+ // return item.items.map((item2) => {
36+ // apply_prefix2(item2, item.link as Chapters);
37+ // });
38+ // } else {
39+ // return apply_prefix(item, prefix);
40+ // }
41+ // }
3742
3843// 给 ChapterItem 的 link 字段追加当前章节的 link 前缀
39- function apply_prefix ( item : ChapterItem , prefix : Chapters ) {
44+ export function apply_prefix ( item : ChapterItem , prefix : Chapters ) {
4045 if ( item ?. link . startsWith ( "/" ) && prefix . endsWith ( "/" ) ) {
4146 return { ...item , link : prefix . slice ( 0 , - 1 ) + item . link } ;
4247 } else if ( ! item . link . startsWith ( "/" ) && ! prefix . endsWith ( "/" ) ) {
@@ -45,7 +50,7 @@ function apply_prefix(item: ChapterItem, prefix: Chapters) {
4550 return { ...item , link : prefix + item . link } ;
4651}
4752
48- const items_xrobot_api = [
53+ export const items_xrobot_api = [
4954 {
5055 text : "API参考" ,
5156 collapsed : false ,
@@ -59,10 +64,30 @@ const items_xrobot_api = [
5964 } ,
6065] ;
6166
62- const items_xrobot_api_server = [ ] ;
63- const items_xrobot_api_client = [ ] ;
67+ export const items_xrobot_api_server = [ ] ;
68+ export const items_xrobot_api_client = [ ] ;
69+
70+ export default {
71+ items_xrobot_api,
72+ items_xrobot_api_client,
73+ items_xrobot_api_server,
74+ } ;
75+
76+ export const items_xrobot_guide_mp = [
77+ {
78+ text : "微信小程序" ,
79+ link : Chapters . xrobot_guide_mp ,
80+ collapsed : true ,
81+ items : [
82+ { text : "智能体管理" , link : "agent-management" } ,
83+ { text : "角色配置" , link : "role-config" } ,
84+ { text : "设备管理" , link : "device-management" } ,
85+ { text : "设备配网" , link : "device-net-config" } ,
86+ ] . map ( ( item ) => apply_prefix ( item , Chapters . xrobot_guide_mp ) ) ,
87+ } ,
88+ ] ;
6489
65- const items_xrobot_guide_device = [
90+ export const items_xrobot_guide_device = [
6691 {
6792 text : "设备使用" ,
6893 link : Chapters . xrobot_guide_device ,
@@ -74,9 +99,24 @@ const items_xrobot_guide_device = [
7499 { text : "智能体连接指南" , link : "device-connection" } ,
75100 ] . map ( ( item ) => apply_prefix ( item , Chapters . xrobot_guide_device ) ) ,
76101 } ,
77- // 子章节
78102] ;
79103
104+ export const items_xrobot_guide = [
105+ {
106+ text : "厂商接入指南" ,
107+ link : Chapters . xrobot_guide ,
108+ collapsed : false ,
109+ items : [ ...items_xrobot_guide_mp , ...items_xrobot_guide_device ] ,
110+ } ,
111+ ] ;
112+
113+ // 判断一个link 字符串是否是章节link
114+ export function isChapter < T extends Record < string , string > > (
115+ link : string
116+ ) : link is T [ keyof T ] {
117+ return Object . values ( Chapters ) . includes ( link as Chapters ) ;
118+ }
119+
80120const items_xrobot_faq = [
81121 {
82122 text : "常见问题" ,
@@ -86,30 +126,6 @@ const items_xrobot_faq = [
86126 apply_prefix ( item , Chapters . xrobot_faq )
87127 ) ,
88128 } ,
89- // 子章节
90- ] ;
91-
92- const items_xrobot_guide_mp = [
93- {
94- text : "微信小程序" ,
95- link : Chapters . xrobot_guide_mp ,
96- collapsed : true ,
97- items : [
98- { text : "智能体管理" , link : "agent-management" } ,
99- { text : "角色配置" , link : "role-config" } ,
100- { text : "设备管理" , link : "device-management" } ,
101- { text : "设备配网" , link : "device-net-config" } ,
102- ] . map ( ( item ) => apply_prefix ( item , Chapters . xrobot_guide_mp ) ) ,
103- } ,
104- ] ;
105-
106- const items_xrobot_guide = [
107- {
108- text : "厂商接入指南" ,
109- link : Chapters . xrobot_guide ,
110- collapsed : false ,
111- items : [ ...items_xrobot_guide_mp , ...items_xrobot_guide_device ] ,
112- } ,
113129] ;
114130
115131// xrobot章节整体
@@ -130,7 +146,6 @@ function gobackItem(chapter: Chapters) {
130146 } ;
131147}
132148
133- // todo: 把子章节从ChapterItems中抽离出来
134149export const ChapterItems : Record < Chapters , ChapterItem [ ] > = {
135150 // main
136151 [ Chapters . xrobot ] : items_xrobot ,
0 commit comments