Make the code easier to read.

This commit is contained in:
2024-06-16 13:22:49 +08:00
parent 37f035709d
commit ed1a6fe662
8 changed files with 71 additions and 41 deletions

View File

@@ -7,9 +7,10 @@ import * as pinyinpro from "pinyin-pro";
interface Props {
collectionName: CollectionKey;
sortedByTimeline: boolean;
sortByTimeline: boolean;
sortByArticleTitle: boolean;
}
const { collectionName, sortedByTimeline } = Astro.props;
const { collectionName, sortByTimeline, sortByArticleTitle } = Astro.props;
type CategoriedPosts = {
[categoryName: string]: Array<CollectionEntry<CollectionKey>>;
@@ -44,7 +45,7 @@ const categoriedPostList: Array<CategoriedPosts> = allCategories.map((key) => {
return postATitle.localeCompare(postBTitle, "en");
}
if (sortedByTimeline) {
if (sortByTimeline) {
// sort article by update date
object[key].sort((postA, postB) => {
// if two articles is updated on the same day, sort them by title
@@ -53,7 +54,7 @@ const categoriedPostList: Array<CategoriedPosts> = allCategories.map((key) => {
}
return sortPostByTitlePinyin(postA, postB);
});
} else {
} else if (sortByArticleTitle) {
// sort article by title
// get articles with titles started in Chinese or the alphabet
let postWithAlphabetStartedTitle: CollectionEntry<keyof ContentEntryMap>[] =