@@ -3,18 +3,8 @@ import { useData } from "vitepress";
33import {
44 ChapterItems ,
55 Chapters ,
6- isChapter ,
76} from " ../../../.vitepress/theme/constrants/route" ;
8-
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- }
7+ import Contents from " ./Contents.vue" ;
188
199const { chapter : chapter_root, root = true } = defineProps <{
2010 // 参数chapter应该是如 Chapter.xrobot_device这样的
@@ -23,16 +13,6 @@ const { chapter: chapter_root, root = true } = defineProps<{
2313 root? : boolean ;
2414}>();
2515
26- const { site } = useData ();
27- const base = site .value .base ;
28-
29- // console.log("contents");
30- let chapter_name: string [] = [];
31- let tocs: { link: string ; text: string }[][] = [];
32-
33- // console.log("chapter_root", chapter_root);
34- // console.log("ChapterItems[chapter_root]", ChapterItems[chapter_root]);
35-
3616const items = ChapterItems [chapter_root ];
3717if (! items ) {
3818 const { page } = useData ();
@@ -44,39 +24,11 @@ if (!items) {
4424 " title:" ,
4525 page .value .title
4626 );
47- } else {
48- items .forEach ((subchapter ) => {
49- // console.log(subchapter);
50- const t = subchapter .items ?.filter ((item ) => {
51- return item .link !== chapter_root && ! item .goback ;
52- });
53- if (t ) {
54- tocs .push (t );
55- chapter_name .push (subchapter .text );
56- }
57- });
5827}
59-
60- // console.log("chapter_name:", chapter_name);
61- // console.log("tocs:", tocs);
6228 </script >
6329
6430<template >
6531 <h2 v-if =" root" >目录</h2 >
6632 <slot name =" header" ></slot >
67- <div v-for =" (subchapter, index) in tocs" >
68- <h3 >{{ chapter_name[index] }}</h3 >
69- <div v-if =" subchapter.length === 0" ><span >暂无内容</span ></div >
70- <ol v-else >
71- <li v-for =" (item, index2) in subchapter" :key =" item.link" >
72- <ol v-if =" isChapter(item.link)" >
73- <ChapterContents
74- :root =" false"
75- :chapter =" item.link as Chapters"
76- ></ChapterContents >
77- </ol >
78- <a v-else :href =" apply_prefix(item.link, base)" >{{ item.text }}</a >
79- </li >
80- </ol >
81- </div >
33+ <Contents :chapter_data =" items" :root =" true" ></Contents >
8234</template >
0 commit comments