UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

116 lines 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileMeta = void 0; exports.newFileMeta = newFileMeta; const paths_1 = require("../../../domain/paths"); /** * FileMeta represents file metadata * Simplified TypeScript version of Go's FileMeta struct */ class FileMeta { constructor(filename = '', openFunc = null) { this.filename = filename; this.componentRoot = ''; this.componentDir = ''; this.openFunc = openFunc; } /** * FileName returns the filename */ fileName() { return this.filename; } /** * RelativeFilename returns the relative filename from root */ relativeFilename() { if (this.componentRoot === '') { return this.filename; } // Find the first occurrence of root in filename const rootIndex = this.filename.indexOf(this.componentRoot); if (rootIndex === -1) { throw new Error(`filename ${this.filename} has no root ${this.componentRoot}`); } // Extract relative path starting from root and remove root part let relativePath = this.filename.substring(rootIndex + this.componentRoot.length); // Ensure path starts with "/" means root directory, with system path separator if (!relativePath.startsWith(paths_1.PATH_CONSTANTS.SYSTEM_PATH_SEPARATOR)) { relativePath = paths_1.PATH_CONSTANTS.SYSTEM_PATH_SEPARATOR + relativePath; } return relativePath; } /** * Component returns the component directory */ component() { return this.componentDir; } /** * Root returns the component root */ root() { return this.componentRoot; } /** * Open opens the file using the OpenFunc */ async open() { if (this.openFunc === null) { throw new Error('OpenFunc not set'); } return await this.openFunc(); } /** * Set the filename */ setFileName(filename) { this.filename = filename; } /** * Set the component root */ setComponentRoot(root) { this.componentRoot = root; } /** * Set the component directory */ setComponentDir(dir) { this.componentDir = dir; } /** * Set the open function */ setOpenFunc(openFunc) { this.openFunc = openFunc; } /** * Merge merges another FileMeta into this one * Only copies non-empty values */ merge(from) { if (!from) return; if (from.filename && !this.filename) { this.filename = from.filename; } if (from.componentRoot && !this.componentRoot) { this.componentRoot = from.componentRoot; } if (from.componentDir && !this.componentDir) { this.componentDir = from.componentDir; } if (from.openFunc && !this.openFunc) { this.openFunc = from.openFunc; } } } exports.FileMeta = FileMeta; /** * Creates a new FileMeta instance */ function newFileMeta(filename, openFunc) { return new FileMeta(filename, openFunc); } //# sourceMappingURL=filemeta.js.map