feat: overwrite prev/next link (#61)

* feat: set Prev/Next to page data

* feat: set links at the bottom of page

* feat: hide next/prev links when themeConfig expressly set false

* feat: disable links when explicity set false

* feat: set customized link when explicity set

* fix: merge import from vitepress
pull/79/head
Yugo Ogura 4 years ago committed by GitHub
parent 5538af6d3d
commit 1b96f631b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,13 +1,42 @@
import { defineComponent, computed } from 'vue'
import { usePageData } from 'vitepress'
import { usePageData, useSiteData } from 'vitepress'
export default defineComponent({
setup() {
const pageData = usePageData()
const siteData = useSiteData()
const resolveLink = (targetLink: string) => {
let target: any = 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(() => {
if (pageData.value.frontmatter.next === false) {
return undefined
}
if (typeof pageData.value.frontmatter.next === 'string') {
return resolveLink(pageData.value.frontmatter.next)
}
return pageData.value.next
})
const prev = computed(() => {
if (pageData.value.frontmatter.prev === false) {
return undefined
}
if (typeof pageData.value.frontmatter.prev === 'string') {
return resolveLink(pageData.value.frontmatter.prev)
}
return pageData.value.prev
})
const hasLinks = computed(() => {

Loading…
Cancel
Save