UNPKG

@mdfriday/foundry

Version:

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

106 lines 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PagesCollector = void 0; const content_1 = require("../../../domain/content"); const log_1 = require("../../../../pkg/log"); // Create a domain-specific logger for content operations const log = (0, log_1.getDomainLogger)('content', { component: 'pagecollector' }); class PagesCollector { constructor(pageMap, fs) { this.processedPaths = new Set(); // Track processed paths this.m = pageMap; this.fs = fs; } /** * Collect - exact replica of Go's Collect method */ async collect() { try { const dirPath = ""; const promptFileSystem = this.fs.contentFs(); const root = await promptFileSystem.stat(dirPath); await this.collectDir(dirPath, root); } catch (error) { log.error(`Failed to collect directory: ${error}`); throw new Error(`Failed to collect directory: ${error}`); } } /** * CollectDir - exact replica of Go's collectDir method */ async collectDir(path, root) { try { await this.fs.walkContent(path, { hookPre: async (dir, path, readdir) => { const fullPath = path; if (this.processedPaths.has(fullPath)) { log.warn('Path already processed!', { path: fullPath, dirName: dir.name(), dirIsDir: dir.isDir(), readdirLength: readdir.length }); return []; } this.processedPaths.add(fullPath); if (readdir.length === 0) { return []; } // const classifier = await Classifier.newClassifier(readdir); // const leaf = classifier.getLeaf(); // if (leaf) { // index.md as normal file // await this.handleBundleLeaf(dir, leaf, path, readdir); // return []; // Skip directory // } for (const fi of readdir) { if (fi.isDir && fi.isDir()) { continue; } const file = (0, content_1.newFileInfo)(fi); await this.m.addFi(file); } return readdir; }, walkFn: async (filePath, fi) => { return; }, }, { info: root }); } catch (error) { // Type error as any to access stack property log.error(`Failed to collect directory: ${error}`, { path, rootName: root.name(), rootIsDir: root.isDir(), stack: error.stack || 'No stack trace available' }); throw new Error(`Failed to collect directory: ${error}`); } } async handleBundleLeaf(dir, bundle, inPath, readdir) { const bundlePath = bundle.paths(); const walk = async (path, info) => { if (info.isDir()) { return; } const f = (0, content_1.newFileInfo)(info); if (info !== bundle.fileInfo()) { if (!f.isLeafBundle() || f.paths().dir() !== bundlePath.dir()) { f.shiftToResource(); } } await this.m.addFi(f); }; await this.fs.walkContent(inPath, { walkFn: walk }, { info: dir, dirEntries: readdir }); } } exports.PagesCollector = PagesCollector; //# sourceMappingURL=pagecollector.js.map