From 09a4fdc9b844a3e1877045afc496282b988f6f6b Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sat, 5 Aug 2023 00:41:08 +0530 Subject: [PATCH] feat(theme): allow customizing prev/next text from config file closes #1373 --- src/client/theme-default/composables/prev-next.ts | 8 ++++++-- src/client/theme-default/support/sidebar.ts | 7 ++++++- types/default-theme.d.ts | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/client/theme-default/composables/prev-next.ts b/src/client/theme-default/composables/prev-next.ts index 6f967f73c073..300e79843d18 100644 --- a/src/client/theme-default/composables/prev-next.ts +++ b/src/client/theme-default/composables/prev-next.ts @@ -31,7 +31,9 @@ export function usePrevNext() { ? frontmatter.value.prev : typeof frontmatter.value.prev === 'object' ? frontmatter.value.prev.text - : undefined) ?? candidates[index - 1]?.text, + : undefined) ?? + candidates[index - 1]?.docFooterText ?? + candidates[index - 1]?.text, link: (typeof frontmatter.value.prev === 'object' ? frontmatter.value.prev.link @@ -45,7 +47,9 @@ export function usePrevNext() { ? frontmatter.value.next : typeof frontmatter.value.next === 'object' ? frontmatter.value.next.text - : undefined) ?? candidates[index + 1]?.text, + : undefined) ?? + candidates[index + 1]?.docFooterText ?? + candidates[index + 1]?.text, link: (typeof frontmatter.value.next === 'object' ? frontmatter.value.next.link diff --git a/src/client/theme-default/support/sidebar.ts b/src/client/theme-default/support/sidebar.ts index 3f7d0b3e663d..955eb23eac7c 100644 --- a/src/client/theme-default/support/sidebar.ts +++ b/src/client/theme-default/support/sidebar.ts @@ -5,6 +5,7 @@ import { isActive } from '../../shared' export interface SidebarLink { text: string link: string + docFooterText?: string } type SidebarItem = DefaultTheme.SidebarItem @@ -71,7 +72,11 @@ export function getFlatSideBarLinks(sidebar: SidebarItem[]): SidebarLink[] { function recursivelyExtractLinks(items: SidebarItem[]) { for (const item of items) { if (item.text && item.link) { - links.push({ text: item.text, link: item.link }) + links.push({ + text: item.text, + link: item.link, + docFooterText: item.docFooterText + }) } if (item.items) { diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index 96b16c841237..4546e7f51705 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -229,6 +229,11 @@ export namespace DefaultTheme { * Base path for the children items. */ base?: string + + /** + * Customize text that appears on the footer of previous/next page. + */ + docFooterText?: string } /**