UNPKG

@mdfriday/foundry

Version:

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

107 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileInfo = void 0; exports.newFileInfo = newFileInfo; exports.newFileInfoWithMeta = newFileInfoWithMeta; const filemeta_1 = require("./filemeta"); /** * FileInfo represents file information with metadata * TypeScript version of Go's FileInfo struct * Implements FileMetaInfo interface */ class FileInfo { constructor(fileInfo, fileMeta) { this.fileInfo = fileInfo; this._fileMeta = fileMeta; } /** * Meta returns the FileMeta */ meta() { return this._fileMeta; } /** * Type returns the file mode */ type() { return this.fileInfo.mode(); } /** * Info returns the underlying FileInfo */ info() { return this.fileInfo; } /** * Set the FileMeta */ setMeta(meta) { this._fileMeta = meta; } // FileInfo interface methods name() { // Return the filename from FileMeta if available, otherwise from underlying fileInfo return this.fileInfo.name(); } size() { return this.fileInfo.size(); } mode() { return this.fileInfo.mode(); } modTime() { return this.fileInfo.modTime(); } isDir() { return this.fileInfo.isDir(); } sys() { return this.fileInfo.sys(); } // FileMeta interface methods (delegated to FileMeta) fileName() { return this._fileMeta.fileName(); } relativeFilename() { return this._fileMeta.relativeFilename(); } component() { return this._fileMeta.component(); } root() { return this._fileMeta.root(); } async open() { return await this._fileMeta.open(); } } exports.FileInfo = FileInfo; /** * Creates a new FileInfo instance */ function newFileInfo(fi, filename) { const meta = (0, filemeta_1.newFileMeta)(filename); const info = new FileInfo(fi, meta); // Check if the FileInfo implements MetaProvider if (isMetaProvider(fi)) { info.meta().merge(fi.meta()); } return info; } /** * Creates a new FileInfo instance with FileMeta */ function newFileInfoWithMeta(fi, meta) { const info = new FileInfo(fi, meta); if (isMetaProvider(fi)) { info.meta().merge(fi.meta()); } return info; } /** * Type guard to check if an object implements MetaProvider */ function isMetaProvider(obj) { return obj && typeof obj.meta === 'function'; } //# sourceMappingURL=fileinfo.js.map