Skip to content

Commit 836a246

Browse files
authored
feat(theme): custom prev/next labels and text (#897)
1 parent 89035d0 commit 836a246

File tree

5 files changed

+84
-7
lines changed

5 files changed

+84
-7
lines changed

docs/config/theme-configs.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,33 @@ export default {
247247

248248
```ts
249249
export interface CarbonAds {
250-
code: string,
250+
code: string
251251
placement: string
252252
}
253253
```
254254

255255
Learn more in [Theme: Carbon Ads](../guide/theme-carbon-ads)
256+
257+
## docFooter
258+
259+
- Type: `DocFooter`
260+
261+
Can be used to customize text appearing above previous and next links. Helpful if not writing docs in English.
262+
263+
```js
264+
export default {
265+
themeConfig: {
266+
docFooter: {
267+
prev: 'Pagina prior',
268+
next: 'Proxima pagina'
269+
}
270+
}
271+
}
272+
```
273+
274+
```ts
275+
export interface DocFooter {
276+
prev?: string
277+
next?: string
278+
}
279+
```

docs/guide/theme-prev-next-link.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
# Prev Next Link
22

3-
Documentation coming soon...
3+
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.
4+
5+
## prev
6+
7+
- Type: `string`
8+
9+
- Details:
10+
11+
Specify the text to show on the link to the previous page.
12+
13+
If you don't set this in frontmatter, the text will be inferred from the sidebar config.
14+
15+
- Example:
16+
17+
```yaml
18+
---
19+
prev: 'Get Started | Markdown'
20+
---
21+
```
22+
23+
## next
24+
25+
- Type: `string`
26+
27+
- Details:
28+
29+
Same as `prev` but for the next page.

src/client/theme-default/components/VPDocFooter.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ const hasLastUpdated = computed(() => {
3636
<div v-if="control.prev || control.next" class="prev-next">
3737
<div class="pager">
3838
<a v-if="control.prev" class="pager-link prev" :href="normalizeLink(control.prev.link)">
39-
<span class="desc">Previous page</span>
39+
<span class="desc">{{ theme.docFooter?.prev ?? 'Previous page' }}</span>
4040
<span class="title">{{ control.prev.text }} </span>
4141
</a>
4242
</div>
4343
<div class="pager" :class="{ 'has-prev': control.prev }">
4444
<a v-if="control.next" class="pager-link next" :href="normalizeLink(control.next.link)">
45-
<span class="desc">Next page</span>
45+
<span class="desc">{{ theme.docFooter?.next ?? 'Next page' }}</span>
4646
<span class="title">{{ control.next.text }}</span>
4747
</a>
4848
</div>

src/client/theme-default/composables/prev-next.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isActive } from '../support/utils'
44
import { getSidebar, getFlatSideBarLinks } from '../support/sidebar'
55

66
export function usePrevNext() {
7-
const { page, theme } = useData()
7+
const { page, theme, frontmatter } = useData()
88

99
return computed(() => {
1010
const sidebar = getSidebar(theme.value.sidebar, page.value.relativePath)
@@ -15,8 +15,12 @@ export function usePrevNext() {
1515
})
1616

1717
return {
18-
prev: candidates[index - 1],
19-
next: candidates[index + 1]
18+
prev: frontmatter.value.prev
19+
? { ...candidates[index - 1], text: frontmatter.value.prev }
20+
: candidates[index - 1],
21+
next: frontmatter.value.next
22+
? { ...candidates[index + 1], text: frontmatter.value.next }
23+
: candidates[index + 1]
2024
}
2125
})
2226
}

types/default-theme.d.ts

+23
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export namespace DefaultTheme {
4343
*/
4444
lastUpdatedText?: string
4545

46+
/**
47+
* Set custom prev/next labels.
48+
*/
49+
docFooter?: DocFooter
50+
4651
/**
4752
* The social links to be displayed at the end of the nav bar. Perfect for
4853
* placing links to social services such as GitHub, Twitter, Facebook, etc.
@@ -157,6 +162,24 @@ export namespace DefaultTheme {
157162
text?: string
158163
}
159164

165+
// prev-next -----------------------------------------------------------------
166+
167+
export interface DocFooter {
168+
/**
169+
* Custom label for previous page button.
170+
*
171+
* @default 'Previous Page'
172+
*/
173+
prev?: string
174+
175+
/**
176+
* Custom label for next page button.
177+
*
178+
* @default 'Next Page'
179+
*/
180+
next?: string
181+
}
182+
160183
// social link ---------------------------------------------------------------
161184

162185
export interface SocialLink {

0 commit comments

Comments
 (0)