refactor: use shared formatDate and SortFn from community packages

This commit is contained in:
saberzero1 2026-04-03 15:08:05 +02:00
parent 89a8411e98
commit 4ec7479cdb
No known key found for this signature in database
8 changed files with 16 additions and 54 deletions

View file

@ -1,6 +1,9 @@
import { formatDate } from '@quartz-community/utils/date';
import { joinSegments, simplifySlug as simplifySlug$1 } from '@quartz-community/utils';
import { jsxs, jsx } from 'preact/jsx-runtime';
// src/components/RecentNotes.tsx
// src/util/lang.ts
function classNames(...classes) {
return classes.filter(Boolean).join(" ");
@ -48,13 +51,6 @@ function getDate(cfg, data) {
}
return data.dates?.[cfg.defaultDateType];
}
function formatDate(d, locale = "en-US") {
return d.toLocaleDateString(locale, {
year: "numeric",
month: "short",
day: "2-digit"
});
}
// src/util/sort.ts
function byDateAndAlphabetical(cfg) {

File diff suppressed because one or more lines are too long

10
dist/index.js vendored
View file

@ -1,6 +1,9 @@
import { formatDate } from '@quartz-community/utils/date';
import { joinSegments, simplifySlug as simplifySlug$1 } from '@quartz-community/utils';
import { jsxs, jsx } from 'preact/jsx-runtime';
// src/components/RecentNotes.tsx
// src/util/lang.ts
function classNames(...classes) {
return classes.filter(Boolean).join(" ");
@ -48,13 +51,6 @@ function getDate(cfg, data) {
}
return data.dates?.[cfg.defaultDateType];
}
function formatDate(d, locale = "en-US") {
return d.toLocaleDateString(locale, {
year: "numeric",
month: "short",
day: "2-digit"
});
}
// src/util/sort.ts
function byDateAndAlphabetical(cfg) {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

19
package-lock.json generated
View file

@ -1049,7 +1049,7 @@
},
"node_modules/@quartz-community/types": {
"version": "0.2.1",
"resolved": "git+ssh://git@github.com/quartz-community/types.git#5786c30b02188ebcccb6f0479205bd6751336015",
"resolved": "git+ssh://git@github.com/quartz-community/types.git#b1dc9ac610c253d0673d1c8c9a695cd4c5aac0ae",
"license": "MIT",
"engines": {
"node": ">=22",
@ -1070,7 +1070,7 @@
},
"node_modules/@quartz-community/utils": {
"version": "0.1.0",
"resolved": "git+ssh://git@github.com/quartz-community/utils.git#8d2e14bcb9efe83ec8085dd0c4f848f3f25a9c78",
"resolved": "git+ssh://git@github.com/quartz-community/utils.git#8b6e32ba07b62500dce10f0c79ca43bb7d7e55bc",
"license": "MIT",
"dependencies": {
"@quartz-community/types": "github:quartz-community/types"
@ -1503,7 +1503,6 @@
"integrity": "sha512-oH72nZRfDv9lADUBSo104Aq7gPHpQZc4BTx38r9xf9pg5LfP6EzSyH2n7qFmmxRQXh7YlUXODcYsg6PuTDSxGg==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"undici-types": "~7.16.0"
}
@ -1555,7 +1554,6 @@
"integrity": "sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg==",
"dev": true,
"license": "BSD-2-Clause",
"peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "7.18.0",
"@typescript-eslint/types": "7.18.0",
@ -1849,7 +1847,6 @@
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@ -2336,7 +2333,6 @@
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"peer": true,
"bin": {
"esbuild": "bin/esbuild"
},
@ -2392,7 +2388,6 @@
"deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
@ -2770,8 +2765,7 @@
"resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-2.0.0.tgz",
"integrity": "sha512-IaOQ9puYtjrkq7Y0Ygl9KDZnrf/aiUJYUpVf89y8kyaxbRG7Y1SrX/jaumrv81vc61+kiMempujsM3Yw7w5qcw==",
"devOptional": true,
"license": "ISC",
"peer": true
"license": "ISC"
},
"node_modules/glob": {
"version": "7.2.3",
@ -2892,7 +2886,6 @@
"integrity": "sha512-zl6s8LwNyo1P9uw+XJGvZtdFF1GdAkOg8ujOw+4Pyb76874fLps4ueHXDhXWdk6YHQ6OgUtinliG7RsYvCbbBg==",
"devOptional": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@types/estree": "^1.0.0",
"@types/hast": "^3.0.0",
@ -4183,7 +4176,6 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"nanoid": "^3.3.11",
"picocolors": "^1.1.1",
@ -4241,7 +4233,6 @@
"resolved": "https://registry.npmjs.org/preact/-/preact-10.28.3.tgz",
"integrity": "sha512-tCmoRkPQLpBeWzpmbhryairGnhW9tKV6c6gr/w+RhoRoKEJwsjzipwp//1oCpGPOchvSLaAPlpcJi9MwMmoPyA==",
"license": "MIT",
"peer": true,
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/preact"
@ -5134,7 +5125,6 @@
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true,
"license": "MIT",
"peer": true,
"engines": {
"node": ">=12"
},
@ -5317,7 +5307,6 @@
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"dev": true,
"license": "Apache-2.0",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@ -5436,7 +5425,6 @@
"integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==",
"devOptional": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@types/unist": "^3.0.0",
"vfile-message": "^4.0.0"
@ -5467,7 +5455,6 @@
"integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"esbuild": "^0.21.3",
"postcss": "^8.4.43",

View file

@ -1,8 +1,9 @@
import type { QuartzComponent, QuartzComponentProps } from "@quartz-community/types";
import { formatDate } from "@quartz-community/utils/date";
import { classNames } from "../util/lang";
import { i18n } from "../i18n";
import { resolveRelative } from "../util/path";
import { getDate, formatDate } from "../util/date";
import { getDate } from "../util/date";
import { byDateAndAlphabetical } from "../util/sort";
import style from "./styles/recentNotes.scss";

View file

@ -16,11 +16,3 @@ export function getDate(cfg: GlobalConfiguration, data: QuartzPluginData): Date
}
return data.dates?.[cfg.defaultDateType];
}
export function formatDate(d: Date, locale: string = "en-US"): string {
return d.toLocaleDateString(locale, {
year: "numeric",
month: "short",
day: "2-digit",
});
}

View file

@ -1,3 +1,4 @@
import type { SortFn } from "@quartz-community/types";
import { getDate } from "./date";
interface GlobalConfiguration {
@ -5,17 +6,6 @@ interface GlobalConfiguration {
[key: string]: unknown;
}
interface QuartzPluginData {
dates?: Record<string, Date>;
frontmatter?: {
title?: string;
[key: string]: unknown;
};
[key: string]: unknown;
}
export type SortFn = (f1: QuartzPluginData, f2: QuartzPluginData) => number;
export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
return (f1, f2) => {
if (f1.dates && f2.dates) {
@ -26,8 +16,8 @@ export function byDateAndAlphabetical(cfg: GlobalConfiguration): SortFn {
return 1;
}
const f1Title = f1.frontmatter?.title?.toLowerCase() ?? "";
const f2Title = f2.frontmatter?.title?.toLowerCase() ?? "";
const f1Title = (f1.frontmatter as { title?: string } | undefined)?.title?.toLowerCase() ?? "";
const f2Title = (f2.frontmatter as { title?: string } | undefined)?.title?.toLowerCase() ?? "";
return f1Title.localeCompare(f2Title);
};
}