Skip to content

Commit a64eacf

Browse files
committed
调整api相关路由;为目录生成组件添加无内容提示
1 parent b0e404c commit a64eacf

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

docs/.vitepress/theme/components/ChapterContents.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const { chapter: chapter_root, root = true } = defineProps<{
1616
let chapter_name: string[] = [];
1717
let tocs: { link: string; text: string }[][] = [];
1818
19-
// console.log(chapter_root);
19+
console.log("chapter_root", chapter_root);
20+
console.log("ChapterItems[chapter_root]", ChapterItems[chapter_root]);
2021
2122
ChapterItems[chapter_root]?.forEach((subchapter) => {
2223
const t = subchapter.items?.filter((item) => {
@@ -28,15 +29,16 @@ ChapterItems[chapter_root]?.forEach((subchapter) => {
2829
}
2930
});
3031
31-
// console.log("chapter_name:", chapter_name);
32-
// console.log("tocs:", tocs);
32+
console.log("chapter_name:", chapter_name);
33+
console.log("tocs:", tocs);
3334
</script>
3435

3536
<template>
3637
<h1 v-if="root">目录</h1>
3738
<div v-for="(subchapter, index) in tocs">
3839
<h2>{{ chapter_name[index] }}</h2>
39-
<ol>
40+
<div v-if="subchapter.length === 0"><span>暂无内容</span></div>
41+
<ol v-else>
4042
<li v-for="(item, index2) in subchapter" :key="item.link">
4143
<ol v-if="isChapter(item.link)">
4244
<ChapterContents

docs/.vitepress/theme/constrants/route.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export enum Chapters {
2222
xrobot_guide_device = "/xrobot/device/",
2323
// api
2424
xrobot_api = "/xrobot/api/",
25-
xrobot_api_server = "/xrobot/api/server",
26-
xrobot_api_client = "/xrobot/api/client",
25+
xrobot_api_server = "/xrobot/api/server/",
26+
xrobot_api_client = "/xrobot/api/client/",
2727
// faq
2828
xrobot_faq = "/xrobot/faq/",
2929
}
@@ -42,6 +42,12 @@ export enum Chapters {
4242

4343
// 给 ChapterItem 的 link 字段追加当前章节的 link 前缀
4444
export function apply_prefix(item: ChapterItem, prefix: Chapters) {
45+
// // 包含子章节
46+
// if (item.items && isChapter(item.link))
47+
// return item.items.map((item2) =>
48+
// apply_prefix(item2, item.link as Chapters)
49+
// );
50+
4551
if (item?.link.startsWith("/") && prefix.endsWith("/")) {
4652
return { ...item, link: prefix.slice(0, -1) + item.link };
4753
} else if (!item.link.startsWith("/") && !prefix.endsWith("/")) {
@@ -50,28 +56,37 @@ export function apply_prefix(item: ChapterItem, prefix: Chapters) {
5056
return { ...item, link: prefix + item.link };
5157
}
5258

53-
export const items_xrobot_api = [
59+
export const items_xrobot_api_server = [
5460
{
55-
text: "API参考",
61+
text: "服务端API参考",
5662
collapsed: false,
57-
link: Chapters.xrobot_api,
63+
link: Chapters.xrobot_api_server,
5864
items: [
5965
{ text: "用户API", link: "user" },
6066
{ text: "智能体API", link: "agent" },
6167
{ text: "设备API", link: "device" },
6268
{ text: "音色克隆API", link: "voice-clone" },
63-
].map((item) => apply_prefix(item, Chapters.xrobot_api)),
69+
].map((item) => apply_prefix(item, Chapters.xrobot_api_server)),
6470
},
6571
];
6672

67-
export const items_xrobot_api_server = [];
68-
export const items_xrobot_api_client = [];
73+
export const items_xrobot_api_client = [
74+
{
75+
text: "客户端API参考",
76+
collapsed: false,
77+
link: Chapters.xrobot_api_client,
78+
items: [].map((item) => apply_prefix(item, Chapters.xrobot_api_client)),
79+
},
80+
];
6981

70-
export default {
71-
items_xrobot_api,
72-
items_xrobot_api_client,
73-
items_xrobot_api_server,
74-
};
82+
export const items_xrobot_api = [
83+
{
84+
text: "API参考",
85+
collapsed: false,
86+
link: Chapters.xrobot_api,
87+
items: [...items_xrobot_api_server, ...items_xrobot_api_client],
88+
},
89+
];
7590

7691
export const items_xrobot_guide_mp = [
7792
{
@@ -140,7 +155,7 @@ const items_xrobot = [
140155

141156
function gobackItem(chapter: Chapters) {
142157
return {
143-
text: "返回上级",
158+
text: "< 返回上级",
144159
link: chapter,
145160
goback: true,
146161
};

docs/xrobot/api/client/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup>
2+
import { Chapters } from "../../../.vitepress/theme/constrants/route";
3+
4+
const chapter_root = Chapters.xrobot_api_client;
5+
</script>
6+
7+
<ChapterContents :chapter=chapter_root />
File renamed without changes.
File renamed without changes.

docs/xrobot/api/server/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup>
2+
import { Chapters } from "../../../.vitepress/theme/constrants/route";
3+
4+
const chapter_root = Chapters.xrobot_api_server;
5+
</script>
6+
7+
<ChapterContents :chapter=chapter_root />
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)