Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: overwrite prev/next link #61

Merged
merged 7 commits into from
Sep 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/client/theme-default/components/NextAndPrevLinks.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down