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

Commit 3fdc6a3

Browse files
fix: default sorter doesn't work fine in Safari (#54)
1 parent 92fae58 commit 3fdc6a3

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Diff for: docs/pagination/README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ Sorter for matched pages, the default sorter is as follows:
1717

1818
```typescript
1919
function sorter(prev: VuePressPage, next: VuePressPage){
20-
const prevTime = new Date(prev.frontmatter.date).getTime()
21-
const nextTime = new Date(next.frontmatter.date).getTime()
20+
const prevTime = new Date(prev.frontmatter.date.replace(/\-/g, '/')).getTime()
21+
const nextTime = new Date(next.frontmatter.date.replace(/\-/g, '/')).getTime()
2222
return prevTime - nextTime > 0 ? -1 : 1
2323
},
2424
```
2525
The function will be a parameter of [Array.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).
2626

27+
::: warning Note
28+
You might be intrigued by `replace(/\-/g, '/')`. Because only the dates in frontmatter written in 2-digits will be transformed, other dates written in single-digit, such as `2020-1-1` will be treated as string. Some browsers (e.g. Safari) don't support this format.
29+
:::
30+
2731
## lengthPerPage
2832

2933
- Type: number
@@ -83,7 +87,7 @@ There are three args to help you customize your title:
8387
- `id` is the id in the [config](../config/#id).
8488
- `scope` is the [key](../config/#keys) while configuring frontmatters or same as `id` while configuring directories.
8589

86-
::: tip TIP
90+
::: warning Note
8791
`${index + 2}`: why `+2`?
8892

8993
Plus 1 since index starts at 0. <br>

Diff for: src/node/util.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,19 @@ export function resolvePaginationConfig(
108108
}
109109
: getFrontmatterClassifierPageFilter(keys),
110110

111+
/**
112+
* You might be intrigued by `replace(/\-/g, '/')`.
113+
* Because only the dates in frontmatter written in 2-digits will be transformed,
114+
* other dates written in single-digit, such as `2020-1-1` will be treated as string.
115+
* Some browsers (e.g. Safari) don't support this format.
116+
*/
111117
sorter: (prev: VuePressPage, next: VuePressPage) => {
112-
const prevTime = new Date(prev.frontmatter.date).getTime();
113-
const nextTime = new Date(next.frontmatter.date).getTime();
118+
const prevTime = new Date(
119+
prev.frontmatter.date.replace(/\-/g, '/')
120+
).getTime();
121+
const nextTime = new Date(
122+
next.frontmatter.date.replace(/\-/g, '/')
123+
).getTime();
114124
return prevTime - nextTime > 0 ? -1 : 1;
115125
},
116126
},

0 commit comments

Comments
 (0)