"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderTemplateFiles = void 0;
const multimatch = require("multimatch");
const async = require("async");
const consolidate_1 = require("consolidate");
const { render } = consolidate_1.handlebars;
function renderTemplateFiles(skipInterpolation) {
    const skipInterpolationOpt = typeof skipInterpolation === 'string' ? [skipInterpolation] : skipInterpolation;
    return (files, metalsmith, done) => {
        const keys = Object.keys(files);
        const metalsmithMetadata = metalsmith.metadata();
        async.each(keys, (file, next) => {
            if (skipInterpolationOpt &&
                multimatch([file], skipInterpolationOpt, { dot: true }).length) {
                return next();
            }
            const str = files[file].contents.toString();
            if (!/{{([^{}]+)}}/g.test(str)) {
                return next();
            }
            render(str, metalsmithMetadata, (err, res) => {
                if (err) {
                    err.message = `[${file}] ${err.message}`;
                    return next(err);
                }
                files[file].contents = Buffer.from(res);
                next();
            });
        }, done);
    };
}
exports.renderTemplateFiles = renderTemplateFiles;
//# sourceMappingURL=renderTemplateFiles.js.map