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 6 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
30 changes: 30 additions & 0 deletions src/client/theme-default/components/NextAndPrevLinks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
import { defineComponent, computed } from 'vue'
import { usePageData } from 'vitepress'
import { useSiteData } from 'vitepress'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge this one with the above import?

Suggested change
import { useSiteData } from 'vitepress'
import { usePageData, useSiteData } from 'vitepress'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
Merged!!


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