@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
41 lines • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceTransformationKey = void 0;
exports.contentReadSeekerCloser = contentReadSeekerCloser;
const crypto_1 = require("crypto");
// ResourceTransformationKey are provided by the different transformation implementations.
// It identifies the transformation (name) and its configuration (elements).
// We combine this in a chain with the rest of the transformations
// with the target filename and a content hash of the origin to use as cache key.
class ResourceTransformationKey {
constructor(name, elements = []) {
this.name = name;
this.elements = elements;
}
static newResourceTransformationKey(name, ...elements) {
return new ResourceTransformationKey(name, elements);
}
// Value returns the Key as a string.
value() {
if (this.elements.length === 0) {
return this.name;
}
const elementsStr = this.hashElements(...this.elements);
return `${this.name}_${elementsStr}`;
}
hashElements(...elements) {
const str = elements.map(e => String(e)).join('|');
return (0, crypto_1.createHash)('sha256').update(str).digest('hex').substring(0, 16);
}
}
exports.ResourceTransformationKey = ResourceTransformationKey;
// ContentReadSeekerCloser returns a ReadSeekerCloser if possible for a given Resource.
async function contentReadSeekerCloser(r) {
try {
return await r.readSeekCloser();
}
catch (error) {
throw new Error(`Cannot transform content of Resource of type ${typeof r}: ${error}`);
}
}
//# sourceMappingURL=transformation.js.map