Skip to content

Commit 1ca9934

Browse files
authored
Merge pull request #5 from hyt1004/main
文档优化
2 parents ffdd218 + f7b339f commit 1ca9934

File tree

143 files changed

+357
-253
lines changed

Some content is hidden

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

143 files changed

+357
-253
lines changed

docs/.vitepress/config.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export default defineConfig({
2727
outline: [2, 4],
2828
nav: [
2929
{ text: "主页", link: "/" },
30-
{ text: "开发文档", link: Chapters.xrobot_platform },
31-
{ text: "API参考", link: Chapters.xrobot_api },
32-
{ text: "最佳实践", link: Chapters.xrobot_platform_esp32 },
30+
{ text: "开发文档", link: Chapters.xrobot },
31+
{ text: "API", link: Chapters.xrobot_api },
32+
{ text: "最佳实践", link: Chapters.xrobot_guide },
3333
{ text: "FAQ", link: Chapters.xrobot_faq },
3434
],
3535
sidebar: sidebarItems,

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@ import {
66
isChapter,
77
} from "../../../.vitepress/theme/constrants/route";
88
9+
function apply_prefix(link: string, prefix: string) {
10+
if (!prefix) return link;
11+
if (link.startsWith("/") && prefix.endsWith("/")) {
12+
return prefix.slice(0, -1) + link;
13+
} else if (!link.startsWith("/") && !prefix.endsWith("/")) {
14+
return prefix + "/" + link;
15+
}
16+
return prefix + link;
17+
}
18+
919
const { chapter: chapter_root, root = true } = defineProps<{
1020
// 参数chapter应该是如 Chapter.xrobot_device这样的
1121
chapter: Chapters;
1222
// root用于控制递归生成目录
1323
root?: boolean;
1424
}>();
1525
26+
const { site } = useData();
27+
const base = site.value.base;
28+
1629
// console.log("contents");
1730
let chapter_name: string[] = [];
1831
let tocs: { link: string; text: string }[][] = [];
@@ -50,6 +63,7 @@ if (!items) {
5063

5164
<template>
5265
<h2 v-if="root">目录</h2>
66+
<slot name="header"></slot>
5367
<div v-for="(subchapter, index) in tocs">
5468
<h3>{{ chapter_name[index] }}</h3>
5569
<div v-if="subchapter.length === 0"><span>暂无内容</span></div>
@@ -61,7 +75,7 @@ if (!items) {
6175
:chapter="item.link as Chapters"
6276
></ChapterContents>
6377
</ol>
64-
<a v-else :href="item.link">{{ item.text }}</a>
78+
<a v-else :href="apply_prefix(item.link, base)">{{ item.text }}</a>
6579
</li>
6680
</ol>
6781
</div>

0 commit comments

Comments
 (0)