Make the code easier to read.
This commit is contained in:
@@ -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>[] =
|
||||
|
||||
Reference in New Issue
Block a user