Skip to content

Commit

Permalink
feat: forward fast glob options, add additional patterns option for f…
Browse files Browse the repository at this point in the history
…iner control
  • Loading branch information
JulianCataldo committed Dec 22, 2024
1 parent 48bd143 commit cdd647b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathsOptions>} CollectOptions
*/
Expand All @@ -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 = [];
Expand Down
6 changes: 3 additions & 3 deletions src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ export async function save(renderedImages, out) {
* @return {Promise<void>}
* */
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);
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/vite-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
});
}

0 comments on commit cdd647b

Please sign in to comment.