diff --git a/src/pages/blog/[page].astro b/src/pages/blog/[page].astro index 839dffc..a85fe17 100644 --- a/src/pages/blog/[page].astro +++ b/src/pages/blog/[page].astro @@ -12,10 +12,12 @@ import PostPreview from "../../components/PostPreview.astro"; import PaginateButton from "../../components/PaginateButton.astro"; import NobbzDev from "../../layouts/NobbzDev.astro"; +import {byDate} from "../../scripts/sorter"; + export const getStaticPaths = (async ({ paginate }) => { const blogEntries = await getCollection("blog").then( (collection: CollectionEntry<"blog">[]) => - collection.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()), + collection.sort(byDate), ); return paginate(blogEntries, { pageSize: 5 }); }) satisfies GetStaticPaths; diff --git a/src/scripts/sorter.ts b/src/scripts/sorter.ts new file mode 100644 index 0000000..490698f --- /dev/null +++ b/src/scripts/sorter.ts @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: 2025 Norbert Melzer +// SPDX-FileContributor: Norbert Melzer +// +// SPDX-License-Identifier: MIT + +export type DateSortable = { + data: { + date: Date; + }; +}; + +export const byDate = (a: DateSortable, b: DateSortable): number => + b.data.date.getTime() - a.data.date.getTime();