Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export default defineConfig({
outline: [2, 4],
nav: [
{ text: "主页", link: "/" },
{ text: "开发文档", link: Chapters.xrobot_platform },
{ text: "API参考", link: Chapters.xrobot_api },
{ text: "最佳实践", link: Chapters.xrobot_platform_esp32 },
{ text: "开发文档", link: Chapters.xrobot },
{ text: "API", link: Chapters.xrobot_api },
{ text: "最佳实践", link: Chapters.xrobot_guide },
{ text: "FAQ", link: Chapters.xrobot_faq },
],
sidebar: sidebarItems,
Expand Down
16 changes: 15 additions & 1 deletion docs/.vitepress/theme/components/ChapterContents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@ import {
isChapter,
} from "../../../.vitepress/theme/constrants/route";

function apply_prefix(link: string, prefix: string) {
if (!prefix) return link;
if (link.startsWith("/") && prefix.endsWith("/")) {
return prefix.slice(0, -1) + link;
} else if (!link.startsWith("/") && !prefix.endsWith("/")) {
return prefix + "/" + link;
}
return prefix + link;
}

const { chapter: chapter_root, root = true } = defineProps<{
// 参数chapter应该是如 Chapter.xrobot_device这样的
chapter: Chapters;
// root用于控制递归生成目录
root?: boolean;
}>();

const { site } = useData();
const base = site.value.base;

// console.log("contents");
let chapter_name: string[] = [];
let tocs: { link: string; text: string }[][] = [];
Expand Down Expand Up @@ -50,6 +63,7 @@ if (!items) {

<template>
<h2 v-if="root">目录</h2>
<slot name="header"></slot>
<div v-for="(subchapter, index) in tocs">
<h3>{{ chapter_name[index] }}</h3>
<div v-if="subchapter.length === 0"><span>暂无内容</span></div>
Expand All @@ -61,7 +75,7 @@ if (!items) {
:chapter="item.link as Chapters"
></ChapterContents>
</ol>
<a v-else :href="item.link">{{ item.text }}</a>
<a v-else :href="apply_prefix(item.link, base)">{{ item.text }}</a>
</li>
</ol>
</div>
Expand Down
Loading