Skip to content

Commit

Permalink
fix: fix frontmatter sidebarDepth for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 14, 2021
1 parent 3f86b7d commit 424a4ca
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/guide/deploy.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebarDepth: 3
---

# Deploying

The following guides are based on some shared assumptions:
Expand Down
3 changes: 3 additions & 0 deletions docs/guide/differences-from-vuepress.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
sidebarDepth: 2
---
# Differences from VuePress

VitePress and VuePress have different [design goals](../index.md). Both projects share similar config naming conventions. VitePress aims to have the bare minimum features needed for authoring docs. Other features are pushed to Themes. On the other hand, VuePress has more features out-of-the-box or enabled by its ecosystem of plugins.
Expand Down
4 changes: 4 additions & 0 deletions docs/guide/markdown.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebarDepth: 3
---

# Markdown Extensions

## Header Anchors
Expand Down
4 changes: 4 additions & 0 deletions docs/guide/using-vue.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebarDepth: 3
---

# Using Vue in Markdown

In VitePress, each markdown file is compiled into HTML and then processed as a Vue Single-File Component. This means you can use any Vue features inside the markdown, including dynamic templating, using Vue components, or arbitrary in-page Vue component logic by adding a `<script>` tag.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebarDepth: 1
sidebarDepth: 2
---

# What is VitePress?
Expand Down
17 changes: 12 additions & 5 deletions src/client/theme-default/components/SideBarLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ interface HeaderWithChildren extends Header {

export const SideBarLink: FunctionalComponent<{
item: DefaultTheme.SideBarItem
depth?: number
}> = (props) => {
const route = useRoute()
const { site } = useData()
const { site, frontmatter } = useData()
const depth = props.depth || 1
const maxDepth = frontmatter.value.sidebarDepth || Infinity

const headers = route.data.headers
const text = props.item.text
const link = resolveLink(site.value.base, props.item.link)
const children = (props.item as DefaultTheme.SideBarGroup).children
const active = isActive(route, props.item.link)
const childItems = createChildren(active, children, headers)
const childItems =
depth < maxDepth
? createChildren(active, children, headers, depth + 1)
: null

return h('li', { class: 'sidebar-link' }, [
h(
Expand Down Expand Up @@ -50,20 +56,21 @@ function resolveLink(base: string, path?: string): string | undefined {
function createChildren(
active: boolean,
children?: DefaultTheme.SideBarItem[],
headers?: Header[]
headers?: Header[],
depth = 1
): VNode | null {
if (children && children.length > 0) {
return h(
'ul',
{ class: 'sidebar-links' },
children.map((c) => {
return h(SideBarLink, { item: c })
return h(SideBarLink, { item: c, depth })
})
)
}

return active && headers
? createChildren(false, resolveHeaders(headers))
? createChildren(false, resolveHeaders(headers), undefined, depth)
: null
}

Expand Down

0 comments on commit 424a4ca

Please sign in to comment.