Skip to content

Commit

Permalink
fix: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian committed Nov 7, 2024
1 parent 190d765 commit b384921
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
46 changes: 44 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
import { SatoriOptions } from 'satori';
import { FormatEnum, Sharp } from 'sharp';
import { OgImage } from './src/OgImage.js';
import TemplateConfig from '@11ty/eleventy/src/TemplateConfig';

export interface OgImage {
inputPath: string;

data: Record<string, any>;

options: EleventyPluginOgImageMergedOptions;

templateConfig: typeof TemplateConfig;

results: {
html?: string;
svg?: string;
pngBuffer?: Buffer;
};

html(): Promise<string>;

svg(): Promise<string>;

pngBuffer(): Promise<Buffer>;

render(): Promise<Sharp>;

hash(): Promise<string>;

outputFileSlug(): Promise<string>;

outputFileName(): Promise<string>;

outputFilePath(): Promise<string>;

outputUrl(): Promise<string>;

cacheFilePath(): Promise<string>;

shortcodeOutput(): Promise<string>;

previewFilePath(): string;

previewHtml(): Promise<string>;
}

type DirectoriesConfig = {
input: string;
Expand All @@ -23,7 +65,7 @@ type EleventyPluginOgImageOptions = {
outputFileSlug?(ogImage: OgImage): Promise<string>;
shortcodeOutput?(ogImage: OgImage): Promise<string>;

OgImage?: typeof OgImage;
OgImage?: OgImage;

satoriOptions?: Partial<SatoriOptions>;
sharpOptions?: SharpFormatOptions;
Expand Down
7 changes: 4 additions & 3 deletions src/OgImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ const require = module.createRequire(import.meta.url);
const Yoga = await initYoga(await fs.readFile(require.resolve('yoga-wasm-web/dist/yoga.wasm')));
init(Yoga);

/** @implements {import('eleventy-plugin-og-image').OgImage} */
export class OgImage {
/** @type {string} */
inputPath;

/** @type {Record<string, any>} */
data;

/** @type {EleventyPluginOgImageMergedOptions} */
/** @type {import('eleventy-plugin-og-image').EleventyPluginOgImageMergedOptions} */
options;

/** @type {import('@11ty/eleventy/src/TemplateConfig').default} */
Expand All @@ -46,7 +47,7 @@ export class OgImage {
/**
* @param {string} inputPath
* @param {Record<string, any>} data
* @param {EleventyPluginOgImageMergedOptions} options
* @param {import('eleventy-plugin-og-image').EleventyPluginOgImageMergedOptions} options
* @param {import('@11ty/eleventy/src/TemplateConfig').default} templateConfig
*/
constructor({ inputPath, data, options, templateConfig }) {
Expand Down Expand Up @@ -88,7 +89,7 @@ export class OgImage {
/**
* Returns the configured output format
*
* @returns {Promise<Sharp>}
* @returns {Promise<import('sharp').Sharp>}
*/
async render() {
return sharp(await this.pngBuffer()).toFormat(this.options.outputFileExtension, this.options.sharpOptions);
Expand Down

0 comments on commit b384921

Please sign in to comment.