Skip to content

Commit 8c8266b

Browse files
committed
fix: treat undefined and false the same when sorting by sticky
Entries without a `sticky` field (undefined) were sorted separately from entries with `sticky: false`, splitting the list into two groups instead of interleaving them by date.
1 parent a59399e commit 8c8266b

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

shared/base.utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ export async function copyEntriesToDist<T extends { slug: string }>(
5959
* @returns negative if a comes first, positive if b comes first
6060
*/
6161
function compareEntries(a: EntryBase, b: EntryBase): number {
62-
// 1. Sticky entries first
63-
if (a.meta.sticky !== b.meta.sticky) {
64-
return a.meta.sticky ? -1 : 1;
62+
// 1. Sticky entries first (treat undefined and false the same)
63+
const aSticky = !!a.meta.sticky;
64+
const bSticky = !!b.meta.sticky;
65+
if (aSticky !== bSticky) {
66+
return aSticky ? -1 : 1;
6567
}
6668
// 2. Then by date (newest first) - ISO 8601 strings sort lexicographically
6769
const dateCompare = b.meta.published.localeCompare(a.meta.published);

0 commit comments

Comments
 (0)