-
Notifications
You must be signed in to change notification settings - Fork 3
/
enhanceAppFile.js
43 lines (41 loc) · 1.34 KB
/
enhanceAppFile.js
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
export default ({ Vue }) => {
Vue.mixin({
computed: {
$sortedPages() {
let sortedPages = []
// 保留草稿功能
// 根据时间进行排序
sortedPages = this.$site.pages
.filter(({ regularPath }) => !regularPath.startsWith('/_draft/'))
.filter(page => page.id)
.map(page => {
page.frontmatter.date = page.frontmatter.date || Date.now()
return page
})
.sort((prev, next) => {
const prevTime = new Date(prev.frontmatter.date).getTime()
const nextTime = new Date(next.frontmatter.date).getTime()
return prevTime - nextTime > 0 ? -1 : 1
})
return sortedPages
},
$pageContext() {
const sortedPages = this.$sortedPages
const currentPageIndex = sortedPages.findIndex(
item => item.regularPath === this.$page.regularPath
)
if (currentPageIndex >= 0) {
const prev = currentPageIndex === 0 ? null : sortedPages[currentPageIndex - 1]
const next =
currentPageIndex === sortedPages.length - 1 ? null : sortedPages[currentPageIndex + 1]
return {
...this.$page,
prev,
next
}
}
return { info: 'this page has no context pages' }
}
}
})
}