UNPKG

@jackdbd/eleventy-plugin-text-to-speech

Version:

Eleventy plugin that uses text-to-speech to generate audio assets for your website, then injects audio players in your HTML.

23 lines 1.08 kB
import defDebug from 'debug'; import { z } from 'zod'; import { collection_name } from '@jackdbd/zod-schemas/eleventy'; import { DEBUG_PREFIX, DEFAULT_COLLECTION_NAME } from '../constants.js'; import { rule } from '../schemas/rule.js'; import { validatedDataOrThrow } from '../validation.js'; export const config_schema = z.object({ rules: z.array(rule).min(1), collectionName: collection_name.default(DEFAULT_COLLECTION_NAME) }); export const templatesWithAudioUnbounded = (config, collectionApi) => { const cfg = validatedDataOrThrow(config, config_schema); const { rules } = cfg; const collectionName = cfg.collectionName || DEFAULT_COLLECTION_NAME; const debug = defDebug(`${DEBUG_PREFIX}:${collectionName}`); const templates = collectionApi.getAll().filter((item) => { const idx = rules.findIndex((rule) => rule.regex && rule.regex.test(item.outputPath)); return idx !== -1; }); debug(`${templates.length} templates in 11ty collection ${collectionName}`); return templates; }; //# sourceMappingURL=collections.js.map