refactor: move defaultDateType to CreatedModifiedDate plugin

This commit is contained in:
saberzero1
2026-03-20 21:13:31 +01:00
parent 28414da76e
commit d9bfbf876f
6 changed files with 11 additions and 23 deletions
+6 -9
View File
@@ -2,16 +2,15 @@ import { FullSlug, isFolderPath, resolveRelative } from "../util/path"
import { QuartzPluginData } from "../plugins/vfile"
import { Date, getDate } from "./Date"
import { QuartzComponent, QuartzComponentProps } from "./types"
import { GlobalConfiguration } from "../cfg"
export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number
export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
export function byDateAndAlphabetical(): SortFn {
return (f1, f2) => {
// Sort by date/alphabetical
if (f1.dates && f2.dates) {
// sort descending
return getDate(cfg, f2)!.getTime() - getDate(cfg, f1)!.getTime()
return getDate(f2)!.getTime() - getDate(f1)!.getTime()
} else if (f1.dates && !f2.dates) {
// prioritize files with dates
return -1
@@ -26,7 +25,7 @@ export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
}
}
export function byDateAndAlphabeticalFolderFirst(cfg: GlobalConfiguration): SortFn {
export function byDateAndAlphabeticalFolderFirst(): SortFn {
return (f1, f2) => {
// Sort folders first
const f1IsFolder = isFolderPath(f1.slug ?? "")
@@ -37,7 +36,7 @@ export function byDateAndAlphabeticalFolderFirst(cfg: GlobalConfiguration): Sort
// If both are folders or both are files, sort by date/alphabetical
if (f1.dates && f2.dates) {
// sort descending
return getDate(cfg, f2)!.getTime() - getDate(cfg, f1)!.getTime()
return getDate(f2)!.getTime() - getDate(f1)!.getTime()
} else if (f1.dates && !f2.dates) {
// prioritize files with dates
return -1
@@ -58,7 +57,7 @@ type Props = {
} & QuartzComponentProps
export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort }: Props) => {
const sorter = sort ?? byDateAndAlphabeticalFolderFirst(cfg)
const sorter = sort ?? byDateAndAlphabeticalFolderFirst()
let list = allFiles.sort(sorter)
if (limit) {
list = list.slice(0, limit)
@@ -73,9 +72,7 @@ export const PageList: QuartzComponent = ({ cfg, fileData, allFiles, limit, sort
return (
<li class="section-li">
<div class="section">
<p class="meta">
{page.dates && <Date date={getDate(cfg, page)!} locale={cfg.locale} />}
</p>
<p class="meta">{page.dates && <Date date={getDate(page)!} locale={cfg.locale} />}</p>
<div class="desc">
<h3>
<a href={resolveRelative(fileData.slug!, page.slug!)} class="internal">