From 8f42fac079c35c86d1c53302a6cfedd041bacc2f Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 17 Jun 2025 00:35:59 -0600 Subject: [PATCH] write my own recent notes sort function --- quartz/components/PageList.tsx | 12 ++++++++++++ quartz/components/RecentNotes.tsx | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/quartz/components/PageList.tsx b/quartz/components/PageList.tsx index 7bf2382..01e0fa8 100644 --- a/quartz/components/PageList.tsx +++ b/quartz/components/PageList.tsx @@ -6,6 +6,18 @@ import { GlobalConfiguration } from "../cfg" export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number +export function byDate(cfg: GlobalConfiguration): SortFn { + return (f1, f2) => { + if (f1.dates && f2.dates) { + // sort descending + return getDate(cfg, f2)!.getTime() - getDate(cfg, f1)!.getTime() + } else { + // prioritize files with dates + return -1 + } + } +} + export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn { return (f1, f2) => { // Sort by date/alphabetical diff --git a/quartz/components/RecentNotes.tsx b/quartz/components/RecentNotes.tsx index 3764b47..a35dfbb 100644 --- a/quartz/components/RecentNotes.tsx +++ b/quartz/components/RecentNotes.tsx @@ -1,7 +1,7 @@ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { FullSlug, SimpleSlug, resolveRelative } from "../util/path" import { QuartzPluginData } from "../plugins/vfile" -import { byDateAndAlphabetical } from "./PageList" +import { byDate } from "./PageList" import style from "./styles/recentNotes.scss" import { Date, getDate } from "./Date" import { GlobalConfiguration } from "../cfg" @@ -22,7 +22,7 @@ const defaultOptions = (cfg: GlobalConfiguration): Options => ({ linkToMore: false, showTags: true, filter: () => true, - sort: byDateAndAlphabetical(cfg), + sort: byDate(cfg), }) export default ((userOpts?: Partial) => {