Skip to content

Commit 1ce602e

Browse files
committed
refactor(core): change page default date to 0000-00-00
BREAKING CHANGE: change page default date from 1970-01-01 to 0000-00-00
1 parent fbe9f99 commit 1ce602e

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

docs/reference/frontmatter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ head:
119119
- The `date` frontmatter.
120120
- The filename that matches the date pattern `yyyy-MM-dd-foobar.md` or `yyyy-MM-foobar.md`.
121121
- The dirname that matches the date pattern `yyyy/MM/dd/foobar.md` or `yyyy/MM/foobar.md`.
122-
- Fallback to `1970-01-01`.
122+
- Fallback to `0000-00-00`.
123123

124124
- Example:
125125

docs/zh/reference/frontmatter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ head:
119119
- Frontmatter 中的 `date` 字段。
120120
- 符合 `yyyy-MM-dd-foobar.md``yyyy-MM-foobar.md` 日期格式的文件名。
121121
- 符合 `yyyy/MM/dd/foobar.md``yyyy/MM/foobar.md` 日期格式的目录名。
122-
- 默认值 `1970-01-01`
122+
- 默认值 `0000-00-00`
123123

124124
- 示例:
125125

packages/@vuepress/core/__tests__/page/createPage.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ describe('core > page > createPage', () => {
2525
expect(page.headers).toEqual([])
2626
expect(page.links).toEqual([])
2727
expect(page.slug).toBe('')
28-
expect(page.date).toBe('1970-01-01')
28+
expect(page.date).toBe('0000-00-00')
2929
})
3030
})

packages/@vuepress/core/__tests__/page/resolvePageDate.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const testCases: [
3232
filePathRelative: null,
3333
},
3434
],
35-
'1970-01-01',
35+
'0000-00-00',
3636
],
3737
// `frontmatter.data` is `undefined`, and relative file path is `null`
3838
[
@@ -42,7 +42,7 @@ const testCases: [
4242
filePathRelative: null,
4343
},
4444
],
45-
'1970-01-01',
45+
'0000-00-00',
4646
],
4747
// filename is empty
4848
[
@@ -52,7 +52,7 @@ const testCases: [
5252
filePathRelative: '',
5353
},
5454
],
55-
'1970-01-01',
55+
'0000-00-00',
5656
],
5757
// filename without date prefix
5858
[
@@ -62,7 +62,7 @@ const testCases: [
6262
filePathRelative: 'foo.md',
6363
},
6464
],
65-
'1970-01-01',
65+
'0000-00-00',
6666
],
6767
// filename with date prefix
6868
[
@@ -92,7 +92,7 @@ const testCases: [
9292
filePathRelative: 'foo/bar.md',
9393
},
9494
],
95-
'1970-01-01',
95+
'0000-00-00',
9696
],
9797
// filename with date prefix, dirname without date prefix
9898
[
@@ -142,7 +142,7 @@ const testCases: [
142142
filePathRelative: '/',
143143
},
144144
],
145-
'1970-01-01',
145+
'0000-00-00',
146146
],
147147
]
148148

packages/@vuepress/core/src/page/resolvePageDate.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PageFrontmatter } from '../types'
44

55
const FILENAME_DATE_RE = /^(\d{4})-(\d{1,2})(?:-(\d{1,2}))?-(.*)$/
66
const DIRNAME_DATE_RE = /(\d{4})\/(\d{1,2})(?:\/(\d{1,2}))?(\/|$)/
7-
const defaultDate = '1970-01-01'
7+
const DEFAULT_DATE = '0000-00-00'
88

99
/**
1010
* Resolve page date according to frontmatter or file path
@@ -26,16 +26,16 @@ export const resolvePageDate = ({
2626
frontmatter.date.getUTCMonth() + 1,
2727
frontmatter.date.getUTCDate(),
2828
].join('-'),
29-
defaultDate
29+
DEFAULT_DATE
3030
)
3131
}
3232

3333
if (isString(frontmatter.date)) {
34-
return formatDateString(frontmatter.date, defaultDate)
34+
return formatDateString(frontmatter.date, DEFAULT_DATE)
3535
}
3636

3737
if (filePathRelative === null) {
38-
return defaultDate
38+
return DEFAULT_DATE
3939
}
4040

4141
const filename = path.parse(filePathRelative).name
@@ -45,7 +45,7 @@ export const resolvePageDate = ({
4545
if (matches) {
4646
return formatDateString(
4747
`${matches[1]}-${matches[2]}-${matches[3] ?? '01'}`,
48-
defaultDate
48+
DEFAULT_DATE
4949
)
5050
}
5151
}
@@ -57,10 +57,10 @@ export const resolvePageDate = ({
5757
if (matches) {
5858
return formatDateString(
5959
`${matches[1]}-${matches[2]}-${matches[3] ?? '01'}`,
60-
defaultDate
60+
DEFAULT_DATE
6161
)
6262
}
6363
}
6464

65-
return defaultDate
65+
return DEFAULT_DATE
6666
}

packages/@vuepress/shared/__tests__/utils/formatDateString.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const testCasesFallback = [
1111
['202-1-1', '1970-01-01'],
1212
['2020-111-1', '1970-01-01'],
1313
['2020-01-001', '1970-01-01'],
14+
['202-1-1', '0000-00-00'],
15+
['2020-111-1', '0000-00-00'],
16+
['2020-01-001', '0000-00-00'],
1417
]
1518

1619
describe('shared > formatDateString', () => {

0 commit comments

Comments
 (0)