Skip to content

Commit

Permalink
feat(vuepress-theme-reco): support time localization
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #255
  • Loading branch information
reco_luan committed Dec 1, 2020
1 parent 1215e56 commit beea671
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
},
socialLinks: [
{ icon: 'reco-github', link: 'https://github.com/recoluan' },
{ icon: 'reco-npm', link: 'https://www.npmjs.com/~reco_luan' }
{ icon: 'fa-camera', link: 'https://www.npmjs.com/~reco_luan' }
]
},
logo: '/head.png',
Expand Down
2 changes: 1 addition & 1 deletion example/en/views/category1/2019/092101.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: second page in category1
title: second page in category12
date: 2019-09-21
tags:
- tag2
Expand Down
2 changes: 1 addition & 1 deletion example/views/category1/2019/092101.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: sidebar test
date: 2019-09-21
date: '2019-09-21'
sidebarDepth: 5
tags:
- tag2
Expand Down
2 changes: 1 addition & 1 deletion packages/vuepress-theme-reco/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default {
return false
},
lastUpdated () {
return this.$page.lastUpdated
return new Date(this.$page.lastUpdated).toLocaleString()
},
lastUpdatedText () {
if (typeof this.$themeLocaleConfig.lastUpdated === 'string') {
Expand Down
22 changes: 3 additions & 19 deletions packages/vuepress-theme-reco/components/PageInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
</template>

<script>
// 引入时间格式化js文件
import { formatDate } from '@theme/helpers/utils'
import { RecoIcon } from '@vuepress-reco/core/lib/components'
export default {
Expand Down Expand Up @@ -68,23 +66,9 @@ export default {
},
filters: {
formatDateValue (value) {
if (!value) return ''
// 返回的value的值都是这个样子2019-09-20T18:22:30.000Z
// 对value进行处理
value = value.replace('T', ' ').slice(0, value.lastIndexOf('.'))
// 转化后的value 2019-09-20 18:22:30
// 获取到时分秒
const h = Number(value.substr(11, 2))
const m = Number(value.substr(14, 2))
const s = Number(value.substr(17, 2))
// 判断时分秒是不是 00:00:00 (如果是用户手动输入的00:00:00也会不显示)
if (h > 0 || m > 0 || s > 0) {
// 时分秒有一个> 0 就说明用户输入一个非 00:00:00 的时分秒
return formatDate(value)
} else {
// 用户没有输入或者输入了 00:00:00
return formatDate(value, 'yyyy-MM-dd')
}
let localDate = new Date(value).toLocaleString()
if (value.split(' ').length === 1) localDate = localDate.split(' ')[0]
return localDate
}
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion packages/vuepress-theme-reco/components/PersonalInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default {
&:hover {
transform scale(1.08)
}
.iconfont {
i {
cursor pointer
font-size 22px
}
Expand Down

0 comments on commit beea671

Please sign in to comment.