diff --git a/package.json b/package.json index 66a7ec9..7187ea3 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "fast-glob": "^3.3.2", "parse5": "^7.2.1", "picocolors": "^1.1.1", - "satori": "^0.10.13", + "satori": "^0.10.14", "satori-html": "^0.3.2" }, "peerDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7bec16b..7b9ce22 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,7 +39,7 @@ importers: specifier: ^4.29.1 version: 4.29.1 satori: - specifier: ^0.10.13 + specifier: ^0.10.14 version: 0.10.14 satori-html: specifier: ^0.3.2 diff --git a/src/collect.js b/src/collect.js index 9bbd6fb..0ec788d 100644 --- a/src/collect.js +++ b/src/collect.js @@ -83,6 +83,8 @@ export function extractMetadataFromHtml(fileContent) { * @property {string} [base] * @property {string} [out] * @property {string} [json] + * @property {string[]} [additionalPatterns] + * @property {import('fast-glob').Options} [globber] * * @typedef {Required} CollectOptions */ @@ -94,7 +96,10 @@ export function extractMetadataFromHtml(fileContent) { export async function collectHtmlPages(options) { console.log(c.bold(c.yellow('Collecting HTML pages…'))); - const files = await fastGlob(path.join(options.base, '**/*.html')); + const files = await fastGlob( + [path.join(options.base, '**/*.html'), ...options.additionalPatterns], + options.globber, + ); /** @type {Page[]} */ const pages = []; diff --git a/src/generate.js b/src/generate.js index 5d3fb7e..e2fae2b 100644 --- a/src/generate.js +++ b/src/generate.js @@ -86,16 +86,16 @@ export async function save(renderedImages, out) { * @return {Promise} * */ export async function generateOgImages(options) { - const config = await loadUserConfig(); - const optionsOrDefaults = { base: options?.base || './dist', out: options?.out || './dist/og', json: options?.json || './dist/og/index.json', + additionalPatterns: options?.additionalPatterns || [], + globber: options?.globber || {}, }; const pages = await collectHtmlPages(optionsOrDefaults); - + const config = await loadUserConfig(); const renderedImages = await renderAllPagesOg(pages, config); await save(renderedImages, optionsOrDefaults.out); diff --git a/src/plugins/vite-plugin.js b/src/plugins/vite-plugin.js index b68dc83..f898d9e 100644 --- a/src/plugins/vite-plugin.js +++ b/src/plugins/vite-plugin.js @@ -17,13 +17,13 @@ export const applyViteDevServerMiddleware = async (server) => { /** * @param {import("../collect").PathsOptions} [options] - * @returns {import('vite').Plugin} + * @returns {any} */ export function viteOgImagesGenerator(options) { - // @ts-expect-error Some incompatible types between Vite and Rollup plugin. - return { + // HACK: Returns as any to prevent Vite typings mismatches. + return /** @type {import('vite').Plugin} */ ({ ...rollupOgImagesGenerator(options), configureServer: (server) => applyViteDevServerMiddleware(server), - }; + }); } diff --git a/test/index.test.js b/test/index.test.js index 686e817..870629e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -5,10 +5,13 @@ import * as api from '../src/api.js'; import { hash } from './_utils.js'; // import { writeFile } from 'node:fs/promises'; +/** @type {import('../src/collect.js').CollectOptions} */ const options = { base: process.cwd() + '/test/__fixtures__/pages', out: process.cwd() + '/test/__fixtures__/.test-outputs', json: process.cwd() + '/test/__fixtures__/.test-outputs/index.json', + additionalPatterns: [], + globber: {}, }; test('Collect HTML pages metadata', async (t) => { @@ -46,7 +49,7 @@ test('Generate single image', async (t) => { }, }); - assert.equal(hash(image), 'ad6a8e499e03a59a1c29e490e7d3f424'); + assert.equal(hash(image), '951fcd6c24e7c6527f2caa3d8cbf32e6'); }); test('Generate single image with async. template', async (t) => { @@ -68,5 +71,5 @@ test('Generate single image with async. template', async (t) => { // image, // ); - assert.equal(hash(image), '62b3609ee5fd7ed967ae24a6682ccdbe'); + assert.equal(hash(image), '0dc1e02ff1f555c937543540ec8acdfc'); });