feat(prev/next-link): make it can be disabled globally

pull/2317/head
donggua 3 years ago
parent 188893c2c1
commit b86382a05b

@ -348,7 +348,10 @@ Learn more in [Default Theme: Carbon Ads](./default-theme-carbon-ads)
- Type: `DocFooter`
Can be used to customize text appearing above previous and next links. Helpful if not writing docs in English.
When the value is a string, it can be used to customize text appearing above previous and next links. Helpful if not writing docs in English.
When the value is `false`, it can be used to disable prev/next links globally. And can be overridden by [frontmatter](https://vitepress.dev/reference/default-theme-prev-next-links)
```js
export default {
@ -363,8 +366,8 @@ export default {
```ts
export interface DocFooter {
prev?: string
next?: string
prev?: string | false
next?: string | false
}
```

@ -14,37 +14,43 @@ export function usePrevNext() {
return isActive(page.value.relativePath, link.link)
})
const hidePrev =
(theme.value.docFooter?.prev === false && !frontmatter.value.prev) ||
frontmatter.value.prev === false
const hideNext =
(theme.value.docFooter?.next === false && !frontmatter.value.next) ||
frontmatter.value.next === false
return {
prev:
frontmatter.value.prev === false
? undefined
: {
text:
(typeof frontmatter.value.prev === 'string'
? frontmatter.value.prev
: typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.text
: undefined) ?? candidates[index - 1]?.text,
link:
(typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.link
: undefined) ?? candidates[index - 1]?.link
},
next:
frontmatter.value.next === false
? undefined
: {
text:
(typeof frontmatter.value.next === 'string'
? frontmatter.value.next
: typeof frontmatter.value.next === 'object'
? frontmatter.value.next.text
: undefined) ?? candidates[index + 1]?.text,
link:
(typeof frontmatter.value.next === 'object'
? frontmatter.value.next.link
: undefined) ?? candidates[index + 1]?.link
}
prev: hidePrev
? undefined
: {
text:
(typeof frontmatter.value.prev === 'string'
? frontmatter.value.prev
: typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.text
: undefined) ?? candidates[index - 1]?.text,
link:
(typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.link
: undefined) ?? candidates[index - 1]?.link
},
next: hideNext
? undefined
: {
text:
(typeof frontmatter.value.next === 'string'
? frontmatter.value.next
: typeof frontmatter.value.next === 'object'
? frontmatter.value.next.text
: undefined) ?? candidates[index + 1]?.text,
link:
(typeof frontmatter.value.next === 'object'
? frontmatter.value.next.link
: undefined) ?? candidates[index + 1]?.link
}
} as {
prev?: { text?: string; link?: string }
next?: { text?: string; link?: string }

@ -234,14 +234,14 @@ export namespace DefaultTheme {
*
* @default 'Previous page'
*/
prev?: string
prev?: string | boolean
/**
* Custom label for next page button.
*
* @default 'Next page'
*/
next?: string
next?: string | boolean
}
// social link ---------------------------------------------------------------

Loading…
Cancel
Save