Skip to content

Commit

Permalink
[v3] remove unnecessary sortPages from server/utils (#3129)
Browse files Browse the repository at this point in the history
  • Loading branch information
87xie authored Aug 21, 2024
1 parent 87b6c08 commit 3c6193d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 94 deletions.
7 changes: 7 additions & 0 deletions .changeset/shy-donuts-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nextra-theme-blog': patch
'nextra-theme-docs': patch
'nextra': patch
---

Remove unnecessary `sortPages` from `server/utils.ts`
64 changes: 0 additions & 64 deletions packages/nextra/__test__/sort-pages.test.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/nextra/src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
} from 'estree'
import slash from 'slash'
import title from 'title'
import type { Folder, MdxFile } from '../types'
import { DEFAULT_PROPERTY_PROPS } from './constants.js'

type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T // from lodash
Expand All @@ -26,35 +25,6 @@ export function pageTitleFromFilename(fileName: string) {
return title(fileName.replaceAll(/[-_]/g, ' '), { special: ['SSR'] })
}

export function sortPages(
pages: (Omit<MdxFile, 'route'> | Omit<Folder, 'route' | 'children'>)[],
locale?: string
): [string, string][] {
return pages
.map(item => ({
name: item.name,
date: 'frontMatter' in item && item.frontMatter?.date,
title:
('frontMatter' in item && item.frontMatter?.title) ||
pageTitleFromFilename(item.name)
}))
.sort((a, b) => {
if (a.date && b.date) {
return new Date(b.date).getTime() - new Date(a.date).getTime()
}
if (a.date) {
return -1 // sort a before b
}
if (b.date) {
return 1 // sort a after b
}
return a.title.localeCompare(b.title, locale || undefined, {
numeric: true
})
})
.map(item => [item.name, item.title])
}

export function normalizePageRoute(parentRoute: string, route: string): string {
return slash(path.join(parentRoute, route.replace(/^index$/, '')))
}
Expand Down

0 comments on commit 3c6193d

Please sign in to comment.