62
62
</template >
63
63
64
64
<script >
65
+ import isString from ' lodash/isString'
66
+ import isNil from ' lodash/isNil'
67
+
65
68
import { resolvePage , outboundRE , endingSlashRE } from ' ../util'
66
69
67
70
export default {
@@ -83,25 +86,11 @@ export default {
83
86
},
84
87
85
88
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 )
94
90
},
95
91
96
92
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 )
105
94
},
106
95
107
96
editLink () {
@@ -161,6 +150,11 @@ export default {
161
150
}
162
151
}
163
152
153
+ const LINK_TYPES = {
154
+ NEXT : ' next' ,
155
+ PREV : ' prev'
156
+ }
157
+
164
158
function resolvePrev (page , items ) {
165
159
return find (page, items, - 1 )
166
160
}
@@ -169,6 +163,29 @@ function resolveNext (page, items) {
169
163
return find (page, items, 1 )
170
164
}
171
165
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
+
172
189
function find (page , items , offset ) {
173
190
const res = []
174
191
flatten (items, res)
0 commit comments