mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 13:24:05 -06:00
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:
parent
f334e78ed6
commit
b50d95005a
@ -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) => {
|
||||
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) {
|
||||
|
||||
@ -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>) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user