Skip to content

Commit e1f98a7

Browse files
committed
文档初始化
1 parent 9dba935 commit e1f98a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3896
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules/
2+
yarn.lock
3+
.DS_Store
4+
# local dist
5+
/dist
6+
7+
docs/.vitepress/cache/
8+
9+
*.mov
10+
11+
test/

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Xrobot-docs
2+
3+
## 安装
4+
5+
``` shell
6+
yarn
7+
```
8+
9+
## 调试
10+
11+
```shell
12+
yarn docs:dev
13+
// 浏览器打开
14+
http://localhost:5173
15+
```
16+

docs/.vitepress/config.mts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig } from "vitepress";
2+
import { ChapterItems, Chapters } from "./theme/constrants/route";
3+
4+
// https://vitepress.dev/reference/site-config
5+
export default defineConfig({
6+
title: "Xrobot Docs",
7+
description: "A Xrobot Documentation Project",
8+
lastUpdated: true,
9+
cleanUrls: true,
10+
locales: {
11+
root: {
12+
label: "简体中文",
13+
lang: "cn",
14+
},
15+
// en: {
16+
// label: "English",
17+
// lang: "en",
18+
// },
19+
},
20+
themeConfig: {
21+
// https://vitepress.dev/reference/default-theme-config
22+
outline: [2, 4],
23+
nav: [
24+
{ text: "主页", link: "/" },
25+
{ text: "设备操作指南", link: Chapters.xrobot_device },
26+
{ text: "API参考", link: Chapters.xrobot_api },
27+
],
28+
sidebar: {
29+
"/": [
30+
{
31+
text: "Examples",
32+
items: [
33+
{ text: "Markdown Examples", link: "/markdown-examples" },
34+
{ text: "Runtime API Examples", link: "/api-examples" },
35+
],
36+
},
37+
],
38+
...ChapterItems,
39+
},
40+
socialLinks: [
41+
{
42+
icon: "github",
43+
link: "https://github.com/realdream-ai/xrobot-miniprogram",
44+
},
45+
],
46+
},
47+
markdown: {
48+
toc: {
49+
level: [1, 2, 3, 4],
50+
},
51+
},
52+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<script setup lang="ts">
2+
import {
3+
ChapterItems,
4+
Chapters,
5+
isChapter,
6+
} from "../../../.vitepress/theme/constrants/route";
7+
8+
const { chapter: chapter_root, root = true } = defineProps<{
9+
// 参数chapter应该是如 Chapter.xrobot_device这样的
10+
chapter: Chapters;
11+
// root用于控制递归生成目录
12+
root?: boolean;
13+
}>();
14+
15+
// console.log("contents");
16+
let chapter_name: string[] = [];
17+
let tocs: { link: string; text: string }[][] = [];
18+
19+
// console.log(chapter_root);
20+
21+
ChapterItems[chapter_root]?.forEach((subchapter) => {
22+
const t = subchapter.items?.filter((item) => {
23+
return item.link !== chapter_root && !item.goback;
24+
});
25+
if (t) {
26+
tocs.push(t);
27+
chapter_name.push(subchapter.text);
28+
}
29+
});
30+
31+
// console.log("chapter_name:", chapter_name);
32+
// console.log("tocs:", tocs);
33+
</script>
34+
35+
<template>
36+
<h1 v-if="root">目录</h1>
37+
<div v-for="(subchapter, index) in tocs">
38+
<h2>{{ chapter_name[index] }}</h2>
39+
<ol>
40+
<li v-for="(item, index2) in subchapter" :key="item.link">
41+
<ol v-if="isChapter(item.link)">
42+
<ChapterContents
43+
:root="false"
44+
:chapter="item.link as Chapters"
45+
></ChapterContents>
46+
</ol>
47+
<a v-else :href="item.link">{{ item.text }}</a>
48+
</li>
49+
</ol>
50+
</div>
51+
</template>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
export type ChapterItem = {
2+
// 标题
3+
text: string;
4+
// 链接
5+
link: string;
6+
// 初始时是否折叠, 如果未指定,侧边栏组不可折叠
7+
collapsed?: boolean;
8+
// 子项
9+
items?: ChapterItem[];
10+
// 返回上级章节
11+
goback?: boolean;
12+
};
13+
14+
// 章节路由,注意,首尾都要有 `/`
15+
// 不在其中的章节不会正确生成目录
16+
export enum Chapters {
17+
// xrobot 分章
18+
xrobot = "/xrobot/",
19+
xrobot_device = "/xrobot/device/",
20+
xrobot_api = "/xrobot/api/",
21+
}
22+
23+
// 判断一个link是否是章节link
24+
export function isChapter<T extends Record<string, string>>(
25+
link: string
26+
): link is T[keyof T] {
27+
return Object.values(Chapters).includes(link);
28+
}
29+
30+
function apply_prefix(item: ChapterItem, prefix: Chapters) {
31+
if (item?.link.startsWith("/") && prefix.endsWith("/")) {
32+
return { ...item, link: prefix.slice(0, -1) + item.link };
33+
} else if (!item.link.startsWith("/") && !prefix.endsWith("/")) {
34+
return { ...item, link: prefix + "/" + item.link };
35+
}
36+
return { ...item, link: prefix + item.link };
37+
}
38+
39+
const items_xrobot_api = [
40+
{
41+
text: "API参考",
42+
items: [
43+
// { text: "章节目录", link: "" },
44+
{ text: "绑定设备", link: "api" },
45+
{ text: "音色克隆", link: "voice-clone" },
46+
].map((item) => apply_prefix(item, Chapters.xrobot_api)),
47+
collapsed: false,
48+
link: Chapters.xrobot_api,
49+
},
50+
];
51+
52+
const items_xrobot_device = [
53+
{
54+
text: "设备指南",
55+
items: [
56+
// { text: "章节目录", link: "" },
57+
{ text: "设备使用指南", link: "device-intro" },
58+
{ text: "设备绑定", link: "device-bind" },
59+
{ text: "设备服务通信协议", link: "device-protocol" },
60+
{ text: "智能体连接指南", link: "device-connection" },
61+
].map((item) => apply_prefix(item, Chapters.xrobot_device)),
62+
link: Chapters.xrobot_device,
63+
collapsed: false,
64+
},
65+
// 子章节
66+
];
67+
68+
// xrobot章节整体
69+
const items_xrobot = [
70+
{
71+
text: "Xrobot",
72+
items: [...items_xrobot_api, ...items_xrobot_device],
73+
link: Chapters.xrobot,
74+
collapsed: false,
75+
},
76+
];
77+
78+
function gobackItem(chapter: Chapters) {
79+
return {
80+
text: "返回上级",
81+
link: chapter,
82+
goback: true,
83+
};
84+
}
85+
86+
// todo: 把子章节从ChapterItems中抽离出来
87+
export const ChapterItems: Record<Chapters, ChapterItem[]> = {
88+
[Chapters.xrobot]: items_xrobot,
89+
[Chapters.xrobot_device]: [
90+
gobackItem(Chapters.xrobot),
91+
...items_xrobot_device,
92+
],
93+
[Chapters.xrobot_api]: [gobackItem(Chapters.xrobot), ...items_xrobot_api],
94+
};

docs/.vitepress/theme/index.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.medium-zoom-overlay {
2+
z-index: 20;
3+
}
4+
5+
.medium-zoom-image {
6+
z-index: 21;
7+
}
8+
9+
/* 图片居中样式 */
10+
.img-center {
11+
display: block;
12+
/* 转为块级元素,确保 margin 生效 */
13+
margin: 0 auto;
14+
/* 水平居中核心 */
15+
/* 可附加其他样式 */
16+
max-width: 100%;
17+
/* 避免图片超出容器 */
18+
/* border: 1px solid #e5e7eb; */
19+
}
20+
21+
div[class="VPContent is-home"] {
22+
/* todo 移除测试背景-该背景被应用到整个页面 */
23+
background: linear-gradient(to bottom right, #dce8ff, #e4eeff, #e6cbfd);
24+
}
25+
26+
html.dark div[class="VPContent is-home"] {
27+
background: none;
28+
}

docs/.vitepress/theme/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import DefaultTheme from "vitepress/theme";
2+
import { onMounted, watch, nextTick } from "vue";
3+
import { useRoute } from "vitepress";
4+
import mediumZoom from "medium-zoom";
5+
6+
import ChapterContents from "./components/ChapterContents.vue";
7+
import MyLayout from "./layout.vue";
8+
9+
import "./index.css";
10+
11+
export default {
12+
...DefaultTheme,
13+
Layout: MyLayout,
14+
enhanceApp({ app }) {
15+
// 注册全局组件
16+
app.component("ChapterContents", ChapterContents);
17+
},
18+
setup() {
19+
const route = useRoute();
20+
const initZoom = () => {
21+
//mediumZoom('[data-zoomable]', { background: 'var(--vp-c-bg)' })
22+
mediumZoom(".main img", { background: "var(--vp-c-bg)" });
23+
};
24+
onMounted(() => {
25+
initZoom();
26+
});
27+
watch(
28+
() => route.path,
29+
() => nextTick(() => initZoom())
30+
);
31+
},
32+
};

docs/.vitepress/theme/layout.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup>
2+
import DefaultTheme from "vitepress/theme";
3+
4+
const { Layout } = DefaultTheme;
5+
</script>
6+
7+
<template>
8+
<Layout>
9+
<!-- <template #home-hero-image> </template> -->
10+
</Layout>
11+
</template>

docs/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
# https://vitepress.dev/reference/default-theme-home-page
3+
layout: home
4+
5+
hero:
6+
name: "Xrobot 文档中心"
7+
text: "Xrobot Docs"
8+
# tagline: ddddddddddddddddddddddddd
9+
actions:
10+
- theme: brand
11+
text: 设备文档
12+
link: /xrobot/
13+
- theme: brand
14+
text: API参考
15+
link: /xrobot/api/
16+
- theme: alt
17+
text: 去体验-七牛小智
18+
link: https://xrobo.qiniu.com/#/home
19+
# features:
20+
# - title:
21+
# details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
22+
# - title: Feature B
23+
# details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
24+
# - title: Feature C
25+
# details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
26+
---

0 commit comments

Comments
 (0)