-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPage.vue
193 lines (175 loc) · 4.89 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<template>
<div>
<div class="page card">
<div class="content-header">
<h1 v-if="title"
class="page-title"
:style="overrideStyle">
{{ title }}
</h1>
<span class="page-timestamp">{{ createTime }}</span>
</div>
<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 id="comment-container" v-if="$site.themeConfig.comment">
<Comment />
</div>
</div>
</div>
</template>
<script>
import OutboundLink from "./components/OutboundLink.vue";
import navLayoutMixin from "./lib/navLayout.mixin";
import Comment from './package/comment';
import {
resolvePage,
normalize,
outboundRE,
endingSlashRE,
pageNormalize
} from "./lib/util";
export default {
mixins: [navLayoutMixin],
components: { OutboundLink, Comment },
props: ["sidebarItems"],
computed: {
prev() {
const prev = this.$page.frontmatter.prev;
if (prev === false) {
return;
} else if (prev) {
return resolvePage(this.pages, prev, this.$route.name);
} else {
return resolvePrev(this.$route.name, this.pages);
}
},
next() {
const next = this.$page.frontmatter.next;
if (next === false) {
return;
} else if (next) {
return resolvePage(this.pages, next, this.$route.name);
} else {
return resolveNext(this.$route.name, this.pages);
}
},
title() {
return this.$page.frontmatter.title;
},
createTime() {
const stamp = this.$page.frontmatter.date;
const format = this.$site.themeConfig["date_format"];
if (!stamp || !format) return "";
const date = new Date(stamp);
return date.Format(format);
},
overrideStyle() {
const accentColor = this.$site.themeConfig["accentColor"];
return accentColor ? { color: accentColor } : {};
},
editLink() {
const {
repo,
editLinks,
docsDir = "",
docsBranch = "master"
} = this.$site.themeConfig;
let path = normalize(this.$page.path);
if (endingSlashRE.test(path)) {
path += "README.md";
} else {
path += ".md";
}
if (repo && editLinks) {
const base = outboundRE.test(repo)
? repo
: `https://github.com/${repo}`;
return (
base.replace(endingSlashRE, "") +
`/edit/${docsBranch}/` +
docsDir.replace(endingSlashRE, "") +
path
);
}
},
editLinkText() {
return (
this.$themeLocaleConfig.editLinkText ||
this.$site.themeConfig.editLinkText ||
`Edit this page`
);
}
}
};
function resolvePrev(name, pages) {
return find(name, pages, -1);
}
function resolveNext(name, pages) {
return find(name, pages, 1);
}
function find(name, pages, offset) {
for (let i = 0; i < pages.length; i++) {
if (pages[i].key === name) {
if (offset < 0 && i === 0) return false;
if (offset > 0 && i === pages.length - 1) return false;
const page = pages[i + offset];
return page.path === "/" ? false : page;
}
}
}
</script>
<style lang="stylus" src="./styles/card.styl"></style>
<style lang="stylus">
@import './styles/config.styl';
#comment-container {
color: #6190E8;
}
.page {
padding-bottom: 2rem;
}
.page-title {
margin-bottom: -2rem;
}
.page-timestamp {
display: block;
font-size: 14px;
margin-top: 2.5rem;
}
.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>