feat(next): sidebar is sorted by title (#232)
parent
dbf74b6780
commit
2547c0ba82
|
@ -1,28 +1,53 @@
|
||||||
import { type DefaultTheme } from 'vitepress'
|
import { type DefaultTheme } from 'vitepress'
|
||||||
import { generateSidebar } from 'vitepress-sidebar'
|
import { SidebarItem, generateSidebar } from 'vitepress-sidebar'
|
||||||
|
|
||||||
export const sidebar = generateSidebar([
|
export const sidebar = generate()
|
||||||
// 大学指南
|
|
||||||
{
|
function generate() {
|
||||||
documentRootPath: '/docs',
|
let sidebar = generateSidebar([
|
||||||
scanStartPath: 'campus',
|
// 大学指南
|
||||||
resolvePath: '/campus/',
|
{
|
||||||
useTitleFromFrontmatter: true,
|
documentRootPath: '/docs',
|
||||||
},
|
scanStartPath: 'campus',
|
||||||
// 贡献指南
|
resolvePath: '/campus/',
|
||||||
{
|
useTitleFromFrontmatter: true,
|
||||||
documentRootPath: '/docs',
|
},
|
||||||
scanStartPath: 'contributor-guide',
|
// 贡献指南
|
||||||
resolvePath: '/contributor-guide/',
|
{
|
||||||
useTitleFromFrontmatter: true,
|
documentRootPath: '/docs',
|
||||||
},
|
scanStartPath: 'contributor-guide',
|
||||||
// Fashion
|
resolvePath: '/contributor-guide/',
|
||||||
{
|
useTitleFromFrontmatter: true,
|
||||||
documentRootPath: '/docs',
|
},
|
||||||
scanStartPath: 'fashion',
|
// Fashion
|
||||||
resolvePath: '/fashion/',
|
{
|
||||||
useTitleFromFrontmatter: true,
|
documentRootPath: '/docs',
|
||||||
|
scanStartPath: 'fashion',
|
||||||
|
resolvePath: '/fashion/',
|
||||||
|
useTitleFromFrontmatter: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 这个 `as` 源于 vitepress-sidebar 的类型定义与实际情况的差异,目前不影响使用,后续 vitepress-sidebar 修复后可以移除。
|
||||||
|
]) as DefaultTheme.Config['sidebar']
|
||||||
|
|
||||||
|
for (const key in sidebar) {
|
||||||
|
sidebar[key].items.sort(sidebarTitleSorter)
|
||||||
}
|
}
|
||||||
|
return sidebar
|
||||||
|
}
|
||||||
|
|
||||||
// 这个 `as` 源于 vitepress-sidebar 的类型定义与实际情况的差异,目前不影响使用,后续 vitepress-sidebar 修复后可以移除。
|
function sidebarTitleSorter(
|
||||||
]) as DefaultTheme.Config['sidebar']
|
infoA: SidebarItem,
|
||||||
|
infoB: SidebarItem
|
||||||
|
): number {
|
||||||
|
const textA = infoA.text
|
||||||
|
const textB = infoB.text
|
||||||
|
if (textA === undefined || textB === undefined) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
const infoANfc = textA.normalize('NFC');
|
||||||
|
const infoBNfc = textB.normalize('NFC');
|
||||||
|
return infoANfc.localeCompare(infoBNfc, 'zh', {
|
||||||
|
numeric: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
"unplugin-vue-components": "^0.26.0",
|
"unplugin-vue-components": "^0.26.0",
|
||||||
"vite": "^5.0.5",
|
"vite": "^5.0.5",
|
||||||
"vitepress": "^1.0.0-rc.31",
|
"vitepress": "^1.0.0-rc.31",
|
||||||
"vitepress-sidebar": "^1.18.0",
|
"vitepress-sidebar": "^1.18.5",
|
||||||
"vue": "^3.3.8",
|
"vue": "^3.3.8",
|
||||||
"vuepress": "2.0.0-rc.0",
|
"vuepress": "2.0.0-rc.0",
|
||||||
"vuepress-theme-hope": "2.0.0-rc.0"
|
"vuepress-theme-hope": "2.0.0-rc.0"
|
||||||
|
|
|
@ -50,8 +50,8 @@ devDependencies:
|
||||||
specifier: ^1.0.0-rc.31
|
specifier: ^1.0.0-rc.31
|
||||||
version: 1.0.0-rc.31(@algolia/client-search@4.20.0)(postcss@8.4.32)(search-insights@2.11.0)
|
version: 1.0.0-rc.31(@algolia/client-search@4.20.0)(postcss@8.4.32)(search-insights@2.11.0)
|
||||||
vitepress-sidebar:
|
vitepress-sidebar:
|
||||||
specifier: ^1.18.0
|
specifier: ^1.18.5
|
||||||
version: 1.18.0
|
version: 1.18.5
|
||||||
vue:
|
vue:
|
||||||
specifier: ^3.3.8
|
specifier: ^3.3.8
|
||||||
version: 3.3.8
|
version: 3.3.8
|
||||||
|
@ -5905,8 +5905,8 @@ packages:
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
fsevents: 2.3.3
|
fsevents: 2.3.3
|
||||||
|
|
||||||
/vitepress-sidebar@1.18.0:
|
/vitepress-sidebar@1.18.5:
|
||||||
resolution: {integrity: sha512-Ki9ZpNa0CUNr7kovAbAEJ5v4MEZi+dte8Bz3OxkQcjFqrOGfQGEoGATRgf9m6N741epLLB3PFdaUCN6ZH0zmhg==}
|
resolution: {integrity: sha512-YksBZrwf6vYpSX+A9ZIa/YjSoiXT0gON2J9va+4FyPYvv31CwufGSjFmobW7IYOYbJEGA7Kl+i5CUo4wVmAvHg==}
|
||||||
engines: {node: '>=18.0.0'}
|
engines: {node: '>=18.0.0'}
|
||||||
dependencies:
|
dependencies:
|
||||||
gray-matter: 4.0.3
|
gray-matter: 4.0.3
|
||||||
|
|
Loading…
Reference in New Issue