-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenhanceApp.js
More file actions
54 lines (50 loc) · 1.7 KB
/
enhanceApp.js
File metadata and controls
54 lines (50 loc) · 1.7 KB
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
// 解决代码选项卡无法加载的问题
import Vue from 'vue'
import Vuetify from 'vuetify'
import 'vuetify/dist/vuetify.min.css'
import CodeBlock from "@theme/global-components/CodeBlock.vue"
import CodeGroup from "@theme/global-components/CodeGroup.vue"
// Register the Vue global component
Vue.component(CodeBlock)
Vue.component(CodeGroup)
import ellipsis from "@theme/assets/js/index.js"
Vue.use(ellipsis)
import "@theme/styles/common.less"
import "@theme/styles/animate.css"
// 注:此文件在浏览器端运行
import postsMixin from '@theme/mixins/posts'
export default ({
Vue, // VuePress 正在使用的 Vue 构造函数
options, // 附加到根实例的一些选项
router, // 当前应用的路由实例
siteData // 站点元数据
}) => {
// 修复ISO8601时间格式为普通时间格式,以及添加作者信息
siteData.pages.map(item => {
const { frontmatter: { date, author } } = item
if (typeof date === 'string' && date.charAt(date.length - 1) === 'Z') {
item.frontmatter.date = repairUTCDate(date)
}
if (author) {
item.author = author
} else {
if (siteData.themeConfig.author) {
item.author = siteData.themeConfig.author
}
}
})
// 将对文章数据的处理结果混入Vue实例
Vue.mixin(postsMixin)
Vue.use(Vuetify)
}
// 修复ISO8601时间格式为普通时间格式
function repairUTCDate (date) {
if (!(date instanceof Date)) {
date = new Date(date)
}
return `${date.getUTCFullYear()}-${zero(date.getUTCMonth() + 1)}-${zero(date.getUTCDate())} ${zero(date.getUTCHours())}:${zero(date.getUTCMinutes())}:${zero(date.getUTCSeconds())}`;
}
// 小于10补0
function zero (d) {
return d.toString().padStart(2, '0')
}