Skip to content

Commit

Permalink
feat: optimize sort by category
Browse files Browse the repository at this point in the history
Compare category by segments intead of its first field
  • Loading branch information
Keith-CY committed Nov 4, 2023
1 parent 9ad2d3c commit 84a0eb8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/blogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ export async function getAllBlogs<F extends (keyof Blog)[]>(sortBy = 'all', pref
}
}
default: {
if (blog1?.category?.startsWith(sortBy) && !blog2?.category?.startsWith(sortBy)) {
const b1Categories = blog1?.category?.split(',') ?? []
const b2Categories = blog2?.category?.split(',') ?? []
if (b1Categories.includes(sortBy) && !b2Categories?.includes(sortBy)) {
return -1
} else if (!blog1?.category?.startsWith(sortBy) && blog2?.category?.startsWith(sortBy)) {
} else if (!b1Categories.includes(sortBy) && b2Categories.includes(sortBy)) {
return 1
} else if (blog1?.date && blog2?.date) {
return blog1?.date > blog2?.date ? -1 : 1
Expand Down

0 comments on commit 84a0eb8

Please sign in to comment.