Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 6c387bd

Browse files
himself65billyyyyy3320
authored andcommitted
feat: support for custom dates (close #25)(#28)
1 parent ce810ff commit 6c387bd

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

docs/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ module.exports = {
2727

2828
## Options
2929

30+
### dateFormat
31+
32+
- Type: `string'
33+
- Default: 'ddd MMM DD YYYY'
34+
35+
You can find all available formats [here](https://github.com/iamkun/dayjs/blob/dev/docs/en/API-reference.md#displaying)
36+
37+
e.g.
38+
39+
```js
40+
module.exports = {
41+
themeConfig: {
42+
dateFormat: 'YYYY-MM-DD'
43+
}
44+
}
45+
```
46+
3047
### nav
3148

3249
- Type: `Array<{ text: string, link: string }>`

example/.vuepress/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ module.exports = {
33
description: 'This is a blog example built by VuePress',
44
theme: require.resolve('../../'),
55
themeConfig: {
6+
/**
7+
* Ref: https://vuepress-theme-blog.ulivz.com/#dateFormat
8+
*/
9+
dateFormat: 'YYYY-MM-DD',
610
/**
711
* Ref: https://vuepress-theme-blog.ulivz.com/#nav
812
*/

global-components/BaseListLayout.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<div v-if="page.frontmatter.date" class="ui-post-date">
2323
<ClockIcon />
24-
<span>{{ resovlePostDate(page.frontmatter.date) }}</span>
24+
<span>{{ resolvePostDate(page.frontmatter.date) }}</span>
2525
</div>
2626
</div>
2727
</div>
@@ -37,6 +37,7 @@
3737
/* global THEME_BLOG_PAGINATION_COMPONENT */
3838
3939
import Vue from 'vue'
40+
import dayjs from 'dayjs'
4041
import { NavigationIcon, ClockIcon } from 'vue-feather-icons'
4142
import {
4243
Pagination,
@@ -76,8 +77,10 @@ export default {
7677
return Vue.component(n) || Pagination
7778
},
7879
79-
resovlePostDate(date) {
80-
return new Date(date.replace(/\-/g, '/').trim()).toDateString()
80+
resolvePostDate(date) {
81+
return dayjs(date).format(
82+
this.$themeConfig.dateFormat || 'ddd MMM DD YYYY'
83+
)
8184
},
8285
},
8386
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@vuepress/plugin-nprogress": "1.0.0",
4848
"@vuepress/plugin-pwa": "1.0.0",
4949
"@vuepress/plugin-search": "1.0.0",
50+
"dayjs": "^1.8.19",
5051
"remove-markdown": "^0.3.0",
5152
"vue-feather-icons": "^4.21.0"
5253
},

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,11 @@ dateformat@^3.0.0:
29732973
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
29742974
integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==
29752975

2976+
dayjs@^1.8.19:
2977+
version "1.8.19"
2978+
resolved "https://registry.npm.taobao.org/dayjs/download/dayjs-1.8.19.tgz#5117dc390d8f8e586d53891dbff3fa308f51abfe"
2979+
integrity sha1-URfcOQ2PjlhtU4kdv/P6MI9Rq/4=
2980+
29762981
de-indent@^1.0.2:
29772982
version "1.0.2"
29782983
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"

0 commit comments

Comments
 (0)