From beec5e0cbbc419fa481d62dc30a3f3577841dee7 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Wed, 4 Dec 2024 08:39:27 -0600 Subject: [PATCH] fix(dates): improve handling of missing dates Make date handling more consistent such that file dates are optional everywhere, i.e. dates are not rendered unless the CreatedModifiedDate plugin sourced the configured date type. --- quartz/components/ContentMeta.tsx | 5 +++-- quartz/components/PageList.tsx | 20 +++++++++----------- quartz/components/RecentNotes.tsx | 7 ++----- quartz/plugins/transformers/lastmod.ts | 13 +++++++------ 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/quartz/components/ContentMeta.tsx b/quartz/components/ContentMeta.tsx index e378bccee..a091a3f2c 100644 --- a/quartz/components/ContentMeta.tsx +++ b/quartz/components/ContentMeta.tsx @@ -29,8 +29,9 @@ export default ((opts?: Partial) => { if (text) { const segments: (string | JSX.Element)[] = [] - if (fileData.dates) { - segments.push() + const date = getDate(cfg, fileData) + if (date) { + segments.push() } // Display reading time if enabled diff --git a/quartz/components/PageList.tsx b/quartz/components/PageList.tsx index 33bd8d730..58b2a1c04 100644 --- a/quartz/components/PageList.tsx +++ b/quartz/components/PageList.tsx @@ -8,13 +8,15 @@ export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn { return (f1, f2) => { - if (f1.dates && f2.dates) { + const f1Date = getDate(cfg, f1) + const f2Date = getDate(cfg, f2) + if (f1Date && f2Date) { // sort descending - return getDate(cfg, f2)!.toMillis() - getDate(cfg, f1)!.toMillis() - } else if (f1.dates && !f2.dates) { + return f2Date.toMillis() - f1Date.toMillis() + } else if (f1Date && !f2Date) { // prioritize files with dates return -1 - } else if (!f1.dates && f2.dates) { + } else if (!f1Date && f2Date) { return 1 } @@ -32,23 +34,19 @@ type Props = { export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => { const sorter = sort ?? byDateAndAlphabetical(cfg) - let list = allFiles.sort(sorter) - if (limit) { - list = list.slice(0, limit) - } + const list = allFiles.toSorted(sorter).slice(0, limit ?? allFiles.length) return (