From b50d95005aad276e04a3a1b40fce2e4783e410e6 Mon Sep 17 00:00:00 2001 From: K Gopal Krishna Date: Fri, 4 Apr 2025 19:05:37 +0530 Subject: [PATCH] Fix(RecentNotes): Prevent folder pages from always appearing first Pass prioritizeFolders=false to byDateAndAlphabetical in RecentNotes to sort strictly by date/alphabetical order, fixing issue #1901. --- quartz/components/PageList.tsx | 14 ++++++++------ quartz/components/RecentNotes.tsx | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/quartz/components/PageList.tsx b/quartz/components/PageList.tsx index 2a5f0e055..e47ccfa7b 100644 --- a/quartz/components/PageList.tsx +++ b/quartz/components/PageList.tsx @@ -6,13 +6,15 @@ import { GlobalConfiguration } from "../cfg" export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number -export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn { +export function byDateAndAlphabetical(cfg: GlobalConfiguration, prioritizeFolders: boolean = true): SortFn { return (f1, f2) => { - // Sort folders first - const f1IsFolder = isFolderPath(f1.slug ?? "") - const f2IsFolder = isFolderPath(f2.slug ?? "") - if (f1IsFolder && !f2IsFolder) return -1 - if (!f1IsFolder && f2IsFolder) return 1 + if (prioritizeFolders) { + // Sort folders first + const f1IsFolder = isFolderPath(f1.slug ?? "") + const f2IsFolder = isFolderPath(f2.slug ?? "") + if (f1IsFolder && !f2IsFolder) return -1 + if (!f1IsFolder && f2IsFolder) return 1 + } // If both are folders or both are files, sort by date/alphabetical if (f1.dates && f2.dates) { diff --git a/quartz/components/RecentNotes.tsx b/quartz/components/RecentNotes.tsx index 2c32feadf..1f6ba42ca 100644 --- a/quartz/components/RecentNotes.tsx +++ b/quartz/components/RecentNotes.tsx @@ -22,7 +22,7 @@ const defaultOptions = (cfg: GlobalConfiguration): Options => ({ linkToMore: false, showTags: true, filter: () => true, - sort: byDateAndAlphabetical(cfg), + sort: byDateAndAlphabetical(cfg, false), }) export default ((userOpts?: Partial) => {