feat: sidebar supported multi level

pull/851/head
yizhi996 3 years ago
parent 00fe8092d9
commit 8b4ce0d88b

@ -5,11 +5,16 @@ import { useData } from 'vitepress'
import { isActive } from '../support/utils' import { isActive } from '../support/utils'
import VPLink from './VPLink.vue' import VPLink from './VPLink.vue'
defineProps<{ withDefaults(defineProps<{
item: DefaultTheme.SidebarItem item: DefaultTheme.SidebarItem
}>() depth?: number
}>(), {
depth: 1
})
const { page } = useData() const { page, frontmatter } = useData()
const maxDepth: number = frontmatter.value.sidebarDepth || Infinity
const closeSideBar = inject('close-sidebar') as () => void const closeSideBar = inject('close-sidebar') as () => void
</script> </script>
@ -20,7 +25,20 @@ const closeSideBar = inject('close-sidebar') as () => void
:href="item.link" :href="item.link"
@click="closeSideBar" @click="closeSideBar"
> >
<span class="link-text">{{ item.text }}</span> <span
class="link-text"
:class="{'link-text-light': depth > 1}">
{{ item.text }}
</span>
<template v-if="depth < maxDepth">
<VPSidebarLink
v-for="child in item.items"
:key="child.link"
:item="child"
:depth="depth + 1"
/>
</template>
</VPLink> </VPLink>
</template> </template>
@ -32,6 +50,10 @@ const closeSideBar = inject('close-sidebar') as () => void
transition: color 0.5s; transition: color 0.5s;
} }
.link>.link {
padding: 4px 0 4px 20px;
}
.link:hover { .link:hover {
color: var(--vp-c-text-1); color: var(--vp-c-text-1);
} }
@ -51,4 +73,9 @@ const closeSideBar = inject('close-sidebar') as () => void
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
} }
.link-text-light {
font-size: 13px;
font-weight: 400;
}
</style> </style>

@ -137,6 +137,7 @@ export namespace DefaultTheme {
export interface SidebarItem { export interface SidebarItem {
text: string text: string
link: string link: string
items?: SidebarItem[]
} }
// edit link ----------------------------------------------------------------- // edit link -----------------------------------------------------------------

Loading…
Cancel
Save