Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nextra] sort
defaultMeta
by frontMatter.date
, if missing by `fro…
…ntMatter.title` and after by capitalized page name + TESTS 🧪 (#894) * sort `defaultMeta` by `frontMatter.date`, if missing by `frontMatter.title` and after by page name * refactor to have less code * Update .changeset/tender-papayas-walk.md * Apply suggestions from code review * capitalize sidebar's folders names if item is missing in `_meta.json` (#895)
- Loading branch information
1 parent
21c8320
commit 094fdec
Showing
6 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'nextra': patch | ||
--- | ||
|
||
sort `defaultMeta` by `frontMatter.date`, if missing by `frontMatter.title` and after by capitalized page name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'nextra': patch | ||
--- | ||
|
||
capitalize sidebar's folders names if item is missing in `_meta.json` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { sortPages } from '../src/utils' | ||
|
||
const kind = 'MdxPage' | ||
|
||
describe('sortPages()', () => { | ||
it('should sort by date', () => { | ||
const data = sortPages([ | ||
{ kind, name: 'baz', frontMatter: { date: new Date('1995-10-21') } }, | ||
{ kind, name: 'foo', frontMatter: { date: new Date('1992-10-21') } }, | ||
{ kind, name: 'quz', frontMatter: { date: new Date('1998-10-21') } } | ||
]) | ||
expect(data).toEqual([ | ||
['quz', 'Quz'], | ||
['baz', 'Baz'], | ||
['foo', 'Foo'] | ||
]) | ||
}) | ||
|
||
it('should sort by date first and after by title', () => { | ||
const data = sortPages([ | ||
{ kind, name: 'quz' }, | ||
{ kind, name: 'foo', frontMatter: { date: new Date('1992-10-21') } }, | ||
{ kind, name: 'baz' } | ||
]) | ||
expect(data).toEqual([ | ||
['foo', 'Foo'], | ||
['baz', 'Baz'], | ||
['quz', 'Quz'] | ||
]) | ||
}) | ||
|
||
it('should take priority `frontMatter.title` over name', () => { | ||
const data = sortPages([ | ||
{ kind, name: 'baz' }, | ||
{ kind, name: 'foo', frontMatter: { title: 'abc' } }, | ||
{ kind, name: 'quz' } | ||
]) | ||
expect(data).toEqual([ | ||
['foo', 'abc'], | ||
['baz', 'Baz'], | ||
['quz', 'Quz'] | ||
]) | ||
}) | ||
|
||
it('should sort numeric', () => { | ||
const data = sortPages([ | ||
{ kind, name: '10-baz' }, | ||
{ kind, name: '0-foo' }, | ||
{ kind, name: '2.5-quz' } | ||
]) | ||
expect(data).toEqual([ | ||
['0-foo', '0 Foo'], | ||
['2.5-quz', '2.5 Quz'], | ||
['10-baz', '10 Baz'] | ||
]) | ||
}) | ||
|
||
it('should capitalize `Folder`', () => { | ||
const data = sortPages([ | ||
{ kind, name: 'quz' }, | ||
{ kind: 'Folder', name: 'foo' }, | ||
{ kind, name: 'baz' } | ||
]) | ||
expect(data).toEqual([ | ||
['baz', 'Baz'], | ||
['foo', 'Foo'], | ||
['quz', 'Quz'] | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters