gpreview
Version:
Preview Ghost themes locally without a full Ghost installation
33 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.preprocessTemplate = preprocessTemplate;
function preprocessTemplate(content) {
try {
const getHelperWithFilterRegex = /(\{\{#get\s+[^}]*?)filter="([^"]*)\{\{([^}]+)\}\}([^"]*)"([^}]*\}\})/g;
return content.replace(getHelperWithFilterRegex, (match, prefix, filterPrefix, variable, filterSuffix, suffix) => {
try {
if (!variable || variable.includes('"') || variable.includes('}')) {
console.warn(`Invalid variable in filter: ${variable}`);
return match;
}
const parts = [];
if (filterPrefix)
parts.push(`"${filterPrefix}"`);
parts.push(variable);
if (filterSuffix)
parts.push(`"${filterSuffix}"`);
const filterValue = parts.length === 1 ? parts[0] : `(concat ${parts.join(' ')})`;
return `${prefix}filter=${filterValue}${suffix}`;
}
catch (error) {
console.error('Error processing filter interpolation:', error);
return match;
}
});
}
catch (error) {
console.error('Error in template preprocessor:', error);
return content;
}
}
//# sourceMappingURL=templatePreprocessor.js.map