mirror of
https://github.com/quartz-community/og-image.git
synced 2026-07-22 02:50:23 +00:00
refactor: use shared getDate from @quartz-community/utils
This commit is contained in:
parent
0ce1e8930f
commit
42b68efe6a
5 changed files with 12 additions and 16 deletions
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
|
|
@ -10,7 +10,7 @@ type Frontmatter = {
|
|||
socialImage?: string;
|
||||
tags?: string[];
|
||||
} & Record<string, unknown>;
|
||||
type QuartzPluginData = {
|
||||
type LocalQuartzPluginData = {
|
||||
slug?: FullSlug;
|
||||
frontmatter?: Frontmatter;
|
||||
description?: string;
|
||||
|
|
@ -37,7 +37,7 @@ type ImageOptions = {
|
|||
description: string;
|
||||
fonts: SatoriOptions["fonts"];
|
||||
cfg: GlobalConfiguration;
|
||||
fileData: QuartzPluginData;
|
||||
fileData: LocalQuartzPluginData;
|
||||
};
|
||||
declare const CustomOgImagesEmitterName = "CustomOgImages";
|
||||
declare const CustomOgImages: QuartzEmitterPlugin<Partial<SocialImageOptions>>;
|
||||
|
|
|
|||
6
dist/index.js
vendored
6
dist/index.js
vendored
|
|
@ -5,6 +5,7 @@ import { styleText } from 'util';
|
|||
import sharp from 'sharp';
|
||||
import { joinSegments } from '@quartz-community/types';
|
||||
import { unescapeHTML } from '@quartz-community/utils';
|
||||
import { getDate } from '@quartz-community/utils/sort';
|
||||
import { getIconCode } from '@quartz-community/utils/emoji';
|
||||
import { jsxs, Fragment, jsx } from 'preact/jsx-runtime';
|
||||
|
||||
|
|
@ -23820,9 +23821,6 @@ function getFileExtension(path2) {
|
|||
function isAbsoluteURL(url) {
|
||||
return /^https?:\/\//.test(url);
|
||||
}
|
||||
function getDate(cfg, data) {
|
||||
return data.dates?.[cfg.defaultDateType ?? "modified"];
|
||||
}
|
||||
function formatDate(d2, locale = "en-US") {
|
||||
return d2.toLocaleDateString(locale, {
|
||||
year: "numeric",
|
||||
|
|
@ -23913,7 +23911,7 @@ var defaultImage = ({
|
|||
const theme = cfg.theme;
|
||||
const fontBreakPoint = 32;
|
||||
const useSmallerFont = title.length > fontBreakPoint;
|
||||
const rawDate = getDate(cfg, fileData);
|
||||
const rawDate = getDate(fileData);
|
||||
const date = rawDate ? formatDate(rawDate, cfg.locale) : null;
|
||||
const { minutes } = (0, import_reading_time.default)(fileData.text ?? "");
|
||||
const readingTimeText = (userOpts.readingTimeText ?? ((time) => `${time} min read`))(
|
||||
|
|
|
|||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1118,7 +1118,7 @@
|
|||
},
|
||||
"node_modules/@quartz-community/types": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "git+ssh://git@github.com/quartz-community/types.git#b1dc9ac610c253d0673d1c8c9a695cd4c5aac0ae",
|
||||
"resolved": "git+ssh://git@github.com/quartz-community/types.git#d413569b02ff0cd9a7e8d74dee125d20a5e5ec72",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=22",
|
||||
|
|
@ -1139,7 +1139,7 @@
|
|||
},
|
||||
"node_modules/@quartz-community/utils": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "git+ssh://git@github.com/quartz-community/utils.git#8b6e32ba07b62500dce10f0c79ca43bb7d7e55bc",
|
||||
"resolved": "git+ssh://git@github.com/quartz-community/utils.git#20b1ac1844ea477b4e32f206a515a5be8d01c56e",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@quartz-community/types": "github:quartz-community/types"
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ import type {
|
|||
FilePath,
|
||||
FullSlug,
|
||||
GlobalConfiguration,
|
||||
QuartzPluginData,
|
||||
} from "@quartz-community/types";
|
||||
import { joinSegments } from "@quartz-community/types";
|
||||
import { unescapeHTML } from "@quartz-community/utils";
|
||||
import { getDate } from "@quartz-community/utils/sort";
|
||||
import type { JSX } from "preact";
|
||||
import { type ThemeKey } from "@quartz-community/types";
|
||||
import { getIconCode } from "@quartz-community/utils/emoji";
|
||||
|
|
@ -30,7 +32,7 @@ type Frontmatter = {
|
|||
tags?: string[];
|
||||
} & Record<string, unknown>;
|
||||
|
||||
type QuartzPluginData = {
|
||||
type LocalQuartzPluginData = {
|
||||
slug?: FullSlug;
|
||||
frontmatter?: Frontmatter;
|
||||
description?: string;
|
||||
|
|
@ -63,10 +65,6 @@ function isAbsoluteURL(url: string): boolean {
|
|||
return /^https?:\/\//.test(url);
|
||||
}
|
||||
|
||||
function getDate(cfg: GlobalConfiguration, data: Record<string, unknown>): Date | undefined {
|
||||
return (data.dates as Record<string, Date> | undefined)?.[cfg.defaultDateType ?? "modified"];
|
||||
}
|
||||
|
||||
function formatDate(d: Date, locale: string = "en-US"): string {
|
||||
return d.toLocaleDateString(locale, {
|
||||
year: "numeric",
|
||||
|
|
@ -192,7 +190,7 @@ export type ImageOptions = {
|
|||
description: string;
|
||||
fonts: SatoriOptions["fonts"];
|
||||
cfg: GlobalConfiguration;
|
||||
fileData: QuartzPluginData;
|
||||
fileData: LocalQuartzPluginData;
|
||||
};
|
||||
|
||||
export const defaultImage: SocialImageOptions["imageStructure"] = ({
|
||||
|
|
@ -208,7 +206,7 @@ export const defaultImage: SocialImageOptions["imageStructure"] = ({
|
|||
const fontBreakPoint = 32;
|
||||
const useSmallerFont = title.length > fontBreakPoint;
|
||||
|
||||
const rawDate = getDate(cfg, fileData);
|
||||
const rawDate = getDate(fileData as QuartzPluginData);
|
||||
const date = rawDate ? formatDate(rawDate, cfg.locale) : null;
|
||||
|
||||
const { minutes } = readingTime(fileData.text ?? "");
|
||||
|
|
|
|||
Loading…
Reference in a new issue