| | |
| | | let processor = unified().use(remarkParse) |
| | | |
| | | // MD AST -> MD AST transforms |
| | | for (const plugin of transformers) { |
| | | processor = processor.use(plugin.markdownPlugins()) |
| | | for (const plugin of transformers.filter(p => p.markdownPlugins)) { |
| | | processor = processor.use(plugin.markdownPlugins!()) |
| | | } |
| | | |
| | | // MD AST -> HTML AST |
| | |
| | | |
| | | |
| | | // HTML AST -> HTML AST transforms |
| | | for (const plugin of transformers) { |
| | | processor = processor.use(plugin.htmlPlugins()) |
| | | for (const plugin of transformers.filter(p => p.htmlPlugins)) { |
| | | processor = processor.use(plugin.htmlPlugins!()) |
| | | } |
| | | |
| | | return processor |
| | |
| | | }) |
| | | } |
| | | |
| | | export function createFileParser(baseDir: string, fps: string[], verbose: boolean) { |
| | | export function createFileParser(transformers: QuartzTransformerPluginInstance[], baseDir: string, fps: string[], verbose: boolean) { |
| | | return async (processor: QuartzProcessor) => { |
| | | const res: ProcessedContent[] = [] |
| | | for (const fp of fps) { |
| | | try { |
| | | const file = await read(fp) |
| | | |
| | | // Text -> Text transforms |
| | | for (const plugin of transformers.filter(p => p.textTransform)) { |
| | | file.value = plugin.textTransform!(file.value) |
| | | } |
| | | |
| | | // base data properties that plugins may use |
| | | file.data.slug = slugify(path.relative(baseDir, file.path)) |
| | | file.data.filePath = fp |
| | |
| | | |
| | | log.start(`Parsing input files using ${concurrency} threads`) |
| | | if (concurrency === 1) { |
| | | // single-thread |
| | | const processor = createProcessor(transformers) |
| | | const parse = createFileParser(baseDir, fps, verbose) |
| | | const parse = createFileParser(transformers, baseDir, fps, verbose) |
| | | res = await parse(processor) |
| | | } else { |
| | | await transpileWorkerScript() |