forked from vuejs/vuepress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.vue
139 lines (128 loc) · 3.27 KB
/
Page.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
<div class="page">
<Content :custom="false"/>
<div class="content edit-link" v-if="editLink">
<a :href="editLink" target="_blank" rel="noopener noreferrer">{{ editLinkText }}</a>
<OutboundLink/>
</div>
<div class="content page-nav" v-if="prev || next">
<p class="inner">
<span v-if="prev" class="prev">
← <router-link v-if="prev" class="prev" :to="prev.path">
{{ prev.title || prev.path }}
</router-link>
</span>
<span v-if="next" class="next">
<router-link v-if="next" :to="next.path">
{{ next.title || next.path }}
</router-link> →
</span>
</p>
</div>
</div>
</template>
<script>
import OutboundLink from './OutboundLink.vue'
import { resolvePage, normalize, outboundRE, endingSlashRE } from './util'
export default {
components: { OutboundLink },
props: ['sidebarItems'],
computed: {
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)
}
},
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)
}
},
editLink () {
const {
repo,
editLinks,
docsDir = '',
docsBranch = 'master'
} = this.$site.themeConfig
const docsRepo = this.$site.themeConfig.docsRepo || repo
let path = normalize(this.$page.path)
if (endingSlashRE.test(path)) {
path += 'README.md'
} else {
path += '.md'
}
if (docsRepo && editLinks) {
const base = outboundRE.test(docsRepo)
? docsRepo
: `https://github.com/${docsRepo}`
return (
base.replace(endingSlashRE, '') +
`/edit/${docsBranch}/` +
docsDir.replace(endingSlashRE, '') +
path
)
}
},
editLinkText () {
return (
this.$themeLocaleConfig.editLinkText ||
this.$site.themeConfig.editLinkText ||
`Edit this page`
)
}
}
}
function resolvePrev (page, items) {
return find(page, items, -1)
}
function resolveNext (page, items) {
return find(page, items, 1)
}
function find (page, items, offset) {
const res = []
items.forEach(item => {
if (item.type === 'group') {
res.push(...item.children || [])
} else {
res.push(item)
}
})
for (let i = 0; i < res.length; i++) {
const cur = res[i]
if (cur.type === 'page' && cur.path === page.path) {
return res[i + offset]
}
}
}
</script>
<style lang="stylus">
@import './styles/config.styl'
.page
padding-bottom 2rem
.edit-link.content
padding-top 0 !important
a
color lighten($textColor, 25%)
margin-right 0.25rem
.page-nav.content
padding-top 1rem !important
padding-bottom 0 !important
.inner
min-height 2rem
margin-top 0 !important
border-top 1px solid $borderColor
padding-top 1rem
.next
float right
</style>