1// SPDX-FileCopyrightText: 2025 Norbert Melzer
2// SPDX-FileContributor: Norbert Melzer
3//
4// SPDX-License-Identifier: MIT
5
6export type DateSortable = {
7 data: {
8 date: Date;
9 };
10};
11
12/**
13 * Can be used for any `ContentCollection` that has a `data.date` field to sort
14 * by it.
15 *
16 * @param a first item to compare
17 * @param b second item to compare
18 * @returns positive number if `a` is older than `b`, negative number if `a` is
19 * newer than `b`
20 */
21export const byDate = (a: DateSortable, b: DateSortable): number =>
22 b.data.date.getTime() - a.data.date.getTime();