From c2c4600e0aad7512a7f0ec6e0cc3b9707bdb89b9 Mon Sep 17 00:00:00 2001 From: Northword Date: Wed, 19 Jun 2024 14:14:54 +0800 Subject: [PATCH] fix: default sort styles by localeCompare --- src/styles/data/styles.data.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/styles/data/styles.data.ts b/src/styles/data/styles.data.ts index fc769f0..b8c77f3 100644 --- a/src/styles/data/styles.data.ts +++ b/src/styles/data/styles.data.ts @@ -10,8 +10,15 @@ export default { load(watchedFiles: string[]) { // watchFiles 是一个所匹配文件的绝对路径的数组。 - return watchedFiles.map((file) => { - return fs.readJsonSync(file); - }); + return watchedFiles + .map((file) => { + return fs.readJsonSync(file) as Style; + }) + .sort((a, b) => { + // title 中包含 GB 的始终最前,否则按预览顺序排序 + if (a.title.match("GB")) return -1; + if (b.title.match("GB")) return 1; + return a.title.localeCompare(b.title); + }); }, };