feat: allow customizing prev/next from frontmatter

pull/897/head
Divyansh Singh 3 years ago
parent 89035d0f28
commit e9b2766b5b

@ -1,3 +1,29 @@
# Prev Next Link
Documentation coming soon...
You can customize the text of previous and next links. This is helpful if you want to show different text on previous/next links than what you have on your sidebar.
## prev
- Type: `string`
- Details:
Specify the text to show on the link to the previous page.
If you don't set this in frontmatter, the text will be inferred from the sidebar config.
- Example:
```yaml
---
prev: 'Get Started | Markdown'
---
```
## next
- Type: `string`
- Details:
Same as `prev` but for the next page.

@ -4,7 +4,7 @@ import { isActive } from '../support/utils'
import { getSidebar, getFlatSideBarLinks } from '../support/sidebar'
export function usePrevNext() {
const { page, theme } = useData()
const { page, theme, frontmatter } = useData()
return computed(() => {
const sidebar = getSidebar(theme.value.sidebar, page.value.relativePath)
@ -15,8 +15,12 @@ export function usePrevNext() {
})
return {
prev: candidates[index - 1],
next: candidates[index + 1]
prev: frontmatter.value.prev
? { ...candidates[index - 1], text: frontmatter.value.prev }
: candidates[index - 1],
next: frontmatter.value.next
? { ...candidates[index + 1], text: frontmatter.value.next }
: candidates[index + 1]
}
})
}

Loading…
Cancel
Save