docs: Sort sidebar (#454)

This commit is contained in:
Dayong Lee 2024-08-31 14:51:58 +09:00 committed by GitHub
parent 14ae504e0f
commit af2d831321
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import { type DefaultTheme, defineConfig } from 'vitepress';
import { sortByText } from '../libs/sortByText.mts';
export const en = defineConfig({
lang: 'en',
@ -44,7 +45,7 @@ function sidebar(): DefaultTheme.Sidebar {
},
{
text: 'Reference',
items: [
items: sortByText([
{
text: 'Array Utilities',
items: [
@ -232,7 +233,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'TimeoutError', link: '/reference/error/TimeoutError' },
],
},
],
]),
},
];
}

View File

@ -1,4 +1,5 @@
import { type DefaultTheme, defineConfig } from 'vitepress';
import { sortByText } from '../libs/sortByText.mts';
export const ja = defineConfig({
lang: 'ja',
@ -43,7 +44,7 @@ function sidebar(): DefaultTheme.Sidebar {
},
{
text: 'リファレンス',
items: [
items: sortByText([
{
text: '配列',
items: [
@ -228,7 +229,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'TimeoutError', link: '/ja/reference/error/TimeoutError' },
],
},
],
]),
},
];
}

View File

@ -1,4 +1,5 @@
import { type DefaultTheme, defineConfig } from 'vitepress';
import { sortByText } from '../libs/sortByText.mts';
export const ko = defineConfig({
lang: 'ko',
@ -43,7 +44,7 @@ function sidebar(): DefaultTheme.Sidebar {
},
{
text: '레퍼런스',
items: [
items: sortByText([
{
text: '배열',
items: [
@ -245,7 +246,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'TimeoutError', link: '/ko/reference/error/TimeoutError' },
],
},
],
]),
},
];
}

View File

@ -1,4 +1,5 @@
import { type DefaultTheme, defineConfig } from 'vitepress';
import { sortByText } from '../libs/sortByText.mts';
// eslint-disable-next-line @typescript-eslint/naming-convention
export const zh_hans = defineConfig({
@ -44,7 +45,7 @@ function sidebar(): DefaultTheme.Sidebar {
},
{
text: '参考',
items: [
items: sortByText([
{
text: '数组工具',
items: [
@ -229,7 +230,7 @@ function sidebar(): DefaultTheme.Sidebar {
{ text: 'TimeoutError', link: '/zh_hans/reference/error/TimeoutError' },
],
},
],
]),
},
];
}

17
docs/libs/sortByText.mts Normal file
View File

@ -0,0 +1,17 @@
import { DefaultTheme } from 'vitepress';
export function sortByText(items: DefaultTheme.SidebarItem[]): DefaultTheme.SidebarItem[] {
return items.slice().map(item => {
if (item.items) {
item.items = item.items.sort((a, b) => {
if (typeof a.text === 'string' && typeof b.text === 'string') {
return a.text.localeCompare(b.text);
}
return 0;
});
}
return item;
});
}