From 5c20fb731059f55116222f6458c07f08f48856a9 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 11 Nov 2023 20:27:51 -0800 Subject: [PATCH] fix: .date.getTime() based sort --- quartz/plugins/emitters/contentIndex.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/quartz/plugins/emitters/contentIndex.ts b/quartz/plugins/emitters/contentIndex.ts index 2c703685..c5170c64 100644 --- a/quartz/plugins/emitters/contentIndex.ts +++ b/quartz/plugins/emitters/contentIndex.ts @@ -6,7 +6,6 @@ import { FilePath, FullSlug, SimpleSlug, simplifySlug } from "../../util/path" import { QuartzEmitterPlugin } from "../types" import { toHtml } from "hast-util-to-html" import path from "path" -import { byDateAndAlphabetical } from "../../components/PageList" export type ContentIndex = Map export type ContentDetails = { @@ -60,7 +59,17 @@ function generateRSSFeed(cfg: GlobalConfiguration, idx: ContentIndex, limit?: nu ` const items = Array.from(idx) - .sort((a, b) => byDateAndAlphabetical(cfg)(a[1], b[1])) + .sort(([_, f1], [__, f2]) => { + if (f1.date && f2.date) { + return f2.date.getTime() - f1.date.getTime() + } else if (f1.date && !f2.date) { + return -1 + } else if (!f1.date && f2.date) { + return 1 + } + + return f1.title.localeCompare(f2.title) + }) .map(([slug, content]) => createURLEntry(simplifySlug(slug), content)) .slice(0, limit ?? idx.size) .join("")