Skip to content

Commit

Permalink
core: allow to disable all next and prev links from global config
Browse files Browse the repository at this point in the history
  • Loading branch information
kefranabg committed Aug 8, 2019
1 parent 7f8b27b commit 665c495
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions packages/@vuepress/theme-default/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
</template>

<script>
import isString from 'lodash/isString'
import isNil from 'lodash/isNil'
import { resolvePage, outboundRE, endingSlashRE } from '../util'
export default {
Expand All @@ -83,25 +86,11 @@ export default {
},
prev () {
const prev = this.$page.frontmatter.prev
if (prev === false) {
return
} else if (prev) {
return resolvePage(this.$site.pages, prev, this.$route.path)
} else {
return resolvePrev(this.$page, this.sidebarItems)
}
return resolvePageLink(LINK_TYPES.PREV, this)
},
next () {
const next = this.$page.frontmatter.next
if (next === false) {
return
} else if (next) {
return resolvePage(this.$site.pages, next, this.$route.path)
} else {
return resolveNext(this.$page, this.sidebarItems)
}
return resolvePageLink(LINK_TYPES.NEXT, this)
},
editLink () {
Expand Down Expand Up @@ -161,6 +150,11 @@ export default {
}
}
const LINK_TYPES = {
NEXT: 'next',
PREV: 'prev'
}
function resolvePrev (page, items) {
return find(page, items, -1)
}
Expand All @@ -169,6 +163,29 @@ function resolveNext (page, items) {
return find(page, items, 1)
}
function resolvePageLink(linkType, { $themeConfig, $page, $route, $site, sidebarItems }) {
const resolveLink = linkType === LINK_TYPES.NEXT ? resolveNext : resolvePrev
// Get link config from theme
const { nextLinks, prevLinks } = $themeConfig
const themeLinkConfig = linkType === LINK_TYPES.NEXT ? nextLinks : prevLinks
// Get link config from current page
const { next, prev } = $page.frontmatter
const pageLinkConfig = linkType === LINK_TYPES.NEXT ? next : prev
// Page link config will overwrite global theme link config if defined
const link = isNil(pageLinkConfig) ? themeLinkConfig : pageLinkConfig
if (link === false) {
return
} else if (isString(link)) {
return resolvePage($site.pages, link, $route.path)
} else {
return resolveLink($page, sidebarItems)
}
}
function find (page, items, offset) {
const res = []
flatten(items, res)
Expand Down

0 comments on commit 665c495

Please sign in to comment.