UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

45 lines (44 loc) 1.9 kB
import { ContentStep } from "ssg-api"; export class RR0ContentStep extends ContentStep { constructor(options, timeService) { super(options.contentConfigs, options.outputFunc, options.name); this.options = options; this.timeService = timeService; this.options.fileVisitors = options.fileVisitors || []; this.options.contentVisitors = options.contentVisitors || []; } async processFile(context, filePath, contentsConfig) { this.timeService.setContextFromFile(context, filePath); return super.processFile(context, filePath, contentsConfig); } async shouldProcessFile(context, contentsConfig) { const fileHasChanged = await super.shouldProcessFile(context, contentsConfig); const fileIsForced = this.options.toProcess.has(context.file.name); const processFile = this.options.force || fileIsForced || fileHasChanged; if (processFile) { this.options.toProcess.add(context.file.name); } for (const fileVisitor of this.options.fileVisitors) { await fileVisitor.visit(context, processFile); } return processFile; } async shouldProcessContent(context, contentsConfig) { const fileIsForced = this.options.toProcess.has(context.file.name); const showProcess = await super.shouldProcessContent(context, contentsConfig); const should = this.options.force || fileIsForced || showProcess; if (should) { for (const contentVisitor of this.options.contentVisitors) { await contentVisitor.visit(context); } } return should; } async postExecute(result) { await super.postExecute(result); for (const fileVisitor of this.options.fileVisitors) { await fileVisitor.contentStepEnd(); } return result; } }