Skip to content

Commit 92a1c02

Browse files
authoredSep 5, 2019
feat: Disable next and prev links from global config (#1761)
* core: add lodash deps * core: disable next and prev links from global config * doc: add documentation * core: resolvePageLink function refactoring * docs: Improve Prev 'Next links' section description
1 parent dad9c8c commit 92a1c02

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed
 

‎packages/@vuepress/theme-default/components/Page.vue

+39-16
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
</template>
6363

6464
<script>
65+
import isString from 'lodash/isString'
66+
import isNil from 'lodash/isNil'
67+
6568
import { resolvePage, outboundRE, endingSlashRE } from '../util'
6669
6770
export default {
@@ -83,25 +86,11 @@ export default {
8386
},
8487
8588
prev () {
86-
const prev = this.$page.frontmatter.prev
87-
if (prev === false) {
88-
return
89-
} else if (prev) {
90-
return resolvePage(this.$site.pages, prev, this.$route.path)
91-
} else {
92-
return resolvePrev(this.$page, this.sidebarItems)
93-
}
89+
return resolvePageLink(LINK_TYPES.PREV, this)
9490
},
9591
9692
next () {
97-
const next = this.$page.frontmatter.next
98-
if (next === false) {
99-
return
100-
} else if (next) {
101-
return resolvePage(this.$site.pages, next, this.$route.path)
102-
} else {
103-
return resolveNext(this.$page, this.sidebarItems)
104-
}
93+
return resolvePageLink(LINK_TYPES.NEXT, this)
10594
},
10695
10796
editLink () {
@@ -169,6 +158,40 @@ function resolveNext (page, items) {
169158
return find(page, items, 1)
170159
}
171160
161+
const LINK_TYPES = {
162+
NEXT: {
163+
resolveLink: resolveNext,
164+
getThemeLinkConfig: ({ nextLinks }) => nextLinks,
165+
getPageLinkConfig: ({ frontmatter }) => frontmatter.next
166+
},
167+
PREV: {
168+
resolveLink: resolvePrev,
169+
getThemeLinkConfig: ({ prevLinks }) => prevLinks,
170+
getPageLinkConfig: ({ frontmatter }) => frontmatter.prev
171+
}
172+
}
173+
174+
function resolvePageLink (linkType, { $themeConfig, $page, $route, $site, sidebarItems }) {
175+
const { resolveLink, getThemeLinkConfig, getPageLinkConfig } = linkType
176+
177+
// Get link config from theme
178+
const themeLinkConfig = getThemeLinkConfig($themeConfig)
179+
180+
// Get link config from current page
181+
const pageLinkConfig = getPageLinkConfig($page)
182+
183+
// Page link config will overwrite global theme link config if defined
184+
const link = isNil(pageLinkConfig) ? themeLinkConfig : pageLinkConfig
185+
186+
if (link === false) {
187+
return
188+
} else if (isString(link)) {
189+
return resolvePage($site.pages, link, $route.path)
190+
} else {
191+
return resolveLink($page, sidebarItems)
192+
}
193+
}
194+
172195
function find (page, items, offset) {
173196
const res = []
174197
flatten(items, res)

‎packages/@vuepress/theme-default/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@vuepress/plugin-nprogress": "^1.0.3",
3535
"@vuepress/plugin-search": "^1.0.3",
3636
"docsearch.js": "^2.5.2",
37+
"lodash": "^4.17.15",
3738
"stylus": "^0.54.5",
3839
"stylus-loader": "^3.0.2",
3940
"vuepress-plugin-container": "^2.0.0"

‎packages/docs/docs/theme/default-theme-config.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ Note that it’s `off` by default. If given a `string`, it will be displayed as
376376

377377
## Prev / Next Links
378378

379-
Prev and next links are automatically inferred based on the sidebar order of the active page. You can also explicitly overwrite or disable them using `YAML front matter`:
379+
Prev and next links are automatically inferred based on the sidebar order of the active page. You can also explicitly overwrite or disable them globally with [theme config](/theme/default-theme-config.html#git-repository-and-edit-links) or on specific pages using `YAML front matter`:
380380

381381
``` yaml
382382
---
@@ -409,17 +409,23 @@ module.exports = {
409409
docsBranch: 'master',
410410
// defaults to false, set to true to enable
411411
editLinks: true,
412+
// default value is true. Allows to hide next page links on all pages
413+
nextLinks: false,
414+
// default value is true. Allows to hide prev page links on all pages
415+
prevLinks: false,
412416
// custom text for edit link. Defaults to "Edit this page"
413417
editLinkText: 'Help us improve this page!'
414418
}
415419
}
416420
```
417421

418-
You can also hide the edit link on a specific page via `YAML front matter`:
422+
You can overwrite the following properties on specific pages via `YAML front matter`:
419423

420424
``` yaml
421425
---
422-
editLink: false
426+
editLink: false # Will overwrite 'editLinks' from themeConfig
427+
prev: true # Will overwrite 'prevLinks' property from themeConfig
428+
next: ./my-next-page # Will overwrite 'nextLinks' property from themeConfig
423429
---
424430
```
425431

‎yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -7316,7 +7316,7 @@ lodash.uniq@^4.5.0:
73167316
version "4.5.0"
73177317
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
73187318

7319-
lodash@^4.0.0, lodash@^4.11.2, lodash@^4.17.12:
7319+
lodash@^4.0.0, lodash@^4.11.2, lodash@^4.17.12, lodash@^4.17.15:
73207320
version "4.17.15"
73217321
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
73227322

0 commit comments

Comments
 (0)
Please sign in to comment.