mirror of https://github.com/vuejs/vitepress
fix: fix next and prev links not working (#130)
parent
f56e745731
commit
fdd498be70
@ -1,61 +0,0 @@
|
||||
import { computed } from 'vue'
|
||||
import { useRoute, useSiteData } from 'vitepress'
|
||||
import { DefaultTheme } from '../config'
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
const route = useRoute()
|
||||
// TODO: could this be useSiteData<DefaultTheme.Config> or is the siteData
|
||||
// resolved and has a different structure?
|
||||
const siteData = useSiteData()
|
||||
|
||||
const resolveLink = (targetLink: string) => {
|
||||
let target: DefaultTheme.SideBarLink | undefined
|
||||
Object.keys(siteData.value.themeConfig.sidebar).some((k) => {
|
||||
return siteData.value.themeConfig.sidebar[k].some(
|
||||
(v: { children: any }) => {
|
||||
if (Array.isArray(v.children)) {
|
||||
target = v.children.find((value: any) => {
|
||||
return value.link === targetLink
|
||||
})
|
||||
}
|
||||
return !!target
|
||||
}
|
||||
)
|
||||
})
|
||||
return target
|
||||
}
|
||||
|
||||
const next = computed(() => {
|
||||
const pageData = route.data
|
||||
if (pageData.frontmatter.next === false) {
|
||||
return undefined
|
||||
}
|
||||
if (typeof pageData.frontmatter.next === 'string') {
|
||||
return resolveLink(pageData.frontmatter.next)
|
||||
}
|
||||
return pageData.next
|
||||
})
|
||||
|
||||
const prev = computed(() => {
|
||||
const pageData = route.data
|
||||
if (pageData.frontmatter.prev === false) {
|
||||
return undefined
|
||||
}
|
||||
if (typeof pageData.frontmatter.prev === 'string') {
|
||||
return resolveLink(pageData.frontmatter.prev)
|
||||
}
|
||||
return pageData.prev
|
||||
})
|
||||
|
||||
const hasLinks = computed(() => {
|
||||
return !!next || !!prev
|
||||
})
|
||||
|
||||
return {
|
||||
next,
|
||||
prev,
|
||||
hasLinks
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue