Skip to content

Commit f19dc20

Browse files
committed
core: disable next and prev links from global config
1 parent 288ac0c commit f19dc20

File tree

1 file changed

+33
-16
lines changed
  • packages/@vuepress/theme-default/components

1 file changed

+33
-16
lines changed

Diff for: packages/@vuepress/theme-default/components/Page.vue

+33-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 () {
@@ -161,6 +150,11 @@ export default {
161150
}
162151
}
163152
153+
const LINK_TYPES = {
154+
NEXT: 'next',
155+
PREV: 'prev'
156+
}
157+
164158
function resolvePrev (page, items) {
165159
return find(page, items, -1)
166160
}
@@ -169,6 +163,29 @@ function resolveNext (page, items) {
169163
return find(page, items, 1)
170164
}
171165
166+
function resolvePageLink (linkType, { $themeConfig, $page, $route, $site, sidebarItems }) {
167+
const resolveLink = linkType === LINK_TYPES.NEXT ? resolveNext : resolvePrev
168+
169+
// Get link config from theme
170+
const { nextLinks, prevLinks } = $themeConfig
171+
const themeLinkConfig = linkType === LINK_TYPES.NEXT ? nextLinks : prevLinks
172+
173+
// Get link config from current page
174+
const { next, prev } = $page.frontmatter
175+
const pageLinkConfig = linkType === LINK_TYPES.NEXT ? next : prev
176+
177+
// Page link config will overwrite global theme link config if defined
178+
const link = isNil(pageLinkConfig) ? themeLinkConfig : pageLinkConfig
179+
180+
if (link === false) {
181+
return
182+
} else if (isString(link)) {
183+
return resolvePage($site.pages, link, $route.path)
184+
} else {
185+
return resolveLink($page, sidebarItems)
186+
}
187+
}
188+
172189
function find (page, items, offset) {
173190
const res = []
174191
flatten(items, res)

0 commit comments

Comments
 (0)