From e9b2766b5b61c297644c4765c74f7043a952641d Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sat, 2 Jul 2022 17:31:16 +0530 Subject: [PATCH] feat: allow customizing prev/next from frontmatter --- docs/guide/theme-prev-next-link.md | 28 ++++++++++++++++++- .../theme-default/composables/prev-next.ts | 10 +++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/guide/theme-prev-next-link.md b/docs/guide/theme-prev-next-link.md index c248d1f3..e52f9057 100644 --- a/docs/guide/theme-prev-next-link.md +++ b/docs/guide/theme-prev-next-link.md @@ -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. diff --git a/src/client/theme-default/composables/prev-next.ts b/src/client/theme-default/composables/prev-next.ts index e09cb0e0..0e97e695 100644 --- a/src/client/theme-default/composables/prev-next.ts +++ b/src/client/theme-default/composables/prev-next.ts @@ -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] } }) }