Fix article sort problem in non-zh environment.
This commit is contained in:
parent
83d584c529
commit
6d4de57e9b
6
package-lock.json
generated
6
package-lock.json
generated
@ -11,6 +11,7 @@
|
||||
"@astrojs/check": "^0.7.0",
|
||||
"@astrojs/sitemap": "^3.1.5",
|
||||
"astro": "^4.9.2",
|
||||
"pinyin-pro": "^3.22.0",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
},
|
||||
@ -4620,6 +4621,11 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/pinyin-pro": {
|
||||
"version": "3.22.0",
|
||||
"resolved": "https://registry.npmmirror.com/pinyin-pro/-/pinyin-pro-3.22.0.tgz",
|
||||
"integrity": "sha512-fz1rvX72K/OmUp3Bbj8/jzRt0aSetmmx/Su4My1H/nUu5x2udnp0Qiq+ojxDXk1CojXBgSUcjXyMI3XNhwSoLg=="
|
||||
},
|
||||
"node_modules/pkg-dir": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/pkg-dir/-/pkg-dir-4.2.0.tgz",
|
||||
|
@ -13,6 +13,7 @@
|
||||
"@astrojs/check": "^0.7.0",
|
||||
"@astrojs/sitemap": "^3.1.5",
|
||||
"astro": "^4.9.2",
|
||||
"pinyin-pro": "^3.22.0",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ import type { CollectionEntry } from "astro:content";
|
||||
import { getCollection, type CollectionKey } from "astro:content";
|
||||
import CategorySummary from "./CategorySummary.astro";
|
||||
|
||||
import * as pinyinpro from "pinyin-pro";
|
||||
|
||||
interface Props {
|
||||
collectionName: CollectionKey;
|
||||
sortedByTimeline: boolean;
|
||||
@ -36,7 +38,13 @@ const categoriedPostList: Array<CategoriedPosts> = allCategories.map((key) => {
|
||||
if (postA.data.lastUpdate !== postB.data.lastUpdate) {
|
||||
return postA.data.lastUpdate < postB.data.lastUpdate ? 1 : -1;
|
||||
}
|
||||
return postA.id.localeCompare(postB.id);
|
||||
let postATitle = pinyinpro.convert(pinyinpro.pinyin(postA.id), {
|
||||
format: "symbolToNum",
|
||||
});
|
||||
let postBTitle = pinyinpro.convert(pinyinpro.pinyin(postB.id), {
|
||||
format: "symbolToNum",
|
||||
});
|
||||
return postATitle.localeCompare(postBTitle);
|
||||
}
|
||||
)
|
||||
: object[key].sort(
|
||||
@ -44,7 +52,13 @@ const categoriedPostList: Array<CategoriedPosts> = allCategories.map((key) => {
|
||||
postA: CollectionEntry<CollectionKey>,
|
||||
postB: CollectionEntry<CollectionKey>
|
||||
) => {
|
||||
return postA.id.localeCompare(postB.id);
|
||||
let postATitle = pinyinpro.convert(pinyinpro.pinyin(postA.id), {
|
||||
format: "symbolToNum",
|
||||
});
|
||||
let postBTitle = pinyinpro.convert(pinyinpro.pinyin(postB.id), {
|
||||
format: "symbolToNum",
|
||||
});
|
||||
return postATitle.localeCompare(postBTitle);
|
||||
}
|
||||
);
|
||||
return object;
|
||||
|
Loading…
Reference in New Issue
Block a user