1
0
mirror of https://gitlab.com/MisterBiggs/brain-quartz.git synced 2025-06-18 18:56:41 +00:00

write my own recent notes sort function

This commit is contained in:
Anson Biggs 2025-06-17 00:35:59 -06:00
parent f1e6d516e6
commit 8f42fac079
2 changed files with 14 additions and 2 deletions

View File

@ -6,6 +6,18 @@ import { GlobalConfiguration } from "../cfg"
export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number 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 { export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
return (f1, f2) => { return (f1, f2) => {
// Sort by date/alphabetical // Sort by date/alphabetical

View File

@ -1,7 +1,7 @@
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
import { FullSlug, SimpleSlug, resolveRelative } from "../util/path" import { FullSlug, SimpleSlug, resolveRelative } from "../util/path"
import { QuartzPluginData } from "../plugins/vfile" import { QuartzPluginData } from "../plugins/vfile"
import { byDateAndAlphabetical } from "./PageList" import { byDate } from "./PageList"
import style from "./styles/recentNotes.scss" import style from "./styles/recentNotes.scss"
import { Date, getDate } from "./Date" import { Date, getDate } from "./Date"
import { GlobalConfiguration } from "../cfg" import { GlobalConfiguration } from "../cfg"
@ -22,7 +22,7 @@ const defaultOptions = (cfg: GlobalConfiguration): Options => ({
linkToMore: false, linkToMore: false,
showTags: true, showTags: true,
filter: () => true, filter: () => true,
sort: byDateAndAlphabetical(cfg), sort: byDate(cfg),
}) })
export default ((userOpts?: Partial<Options>) => { export default ((userOpts?: Partial<Options>) => {