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.
This commit is contained in:
K Gopal Krishna 2025-04-04 19:05:37 +05:30
parent f334e78ed6
commit b50d95005a
2 changed files with 9 additions and 7 deletions

View File

@ -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) {

View File

@ -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<Options>) => {