UNPKG

@mdfriday/foundry

Version:

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

133 lines 5.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Output = void 0; const content_1 = require("../../../domain/content"); class Output { constructor(source, pageKind) { this.target = null; this.source = source; this.pageKind = pageKind; this.baseName = ""; this.setBasename(); this.buildTarget(); } // Mimics Go's setBasename() method setBasename() { switch (this.pageKind) { case (0, content_1.getKindMain)("404"): this.baseName = "404"; break; case (0, content_1.getKindMain)("sitemap"): this.baseName = "sitemap"; break; default: this.baseName = this.source.paths().baseNameNoIdentifier() || "index"; break; } } // Build single HTML target (since user only wants HTML format) buildTarget() { // Simplified path building logic based on Go version let filePath = ""; let subResourceBaseTarget = ""; // CRITICAL FIX: Use HTML format's BaseName ("index") like golang's f.BaseName // This matches golang's buildSection: pb.Add(f.BaseName + pb.FullSuffix) const htmlFormatBaseName = "index"; // HTMLFormat.BaseName from golang switch (this.pageKind) { case (0, content_1.getKindMain)("home"): filePath = `${htmlFormatBaseName}.html`; subResourceBaseTarget = ""; break; case (0, content_1.getKindMain)("page"): const dir = this.source.paths().containerDir(); if (!dir || dir === '/') { filePath = `/${this.baseName}.html`; } else { filePath = `${dir}/${this.baseName}.html`; } subResourceBaseTarget = dir || ""; break; case (0, content_1.getKindMain)("section"): case (0, content_1.getKindMain)("taxonomy"): case (0, content_1.getKindMain)("term"): // CRITICAL: Use htmlFormatBaseName ("index") not this.baseName // This matches golang's buildSection: pb.Add(f.BaseName + pb.FullSuffix) const sectionDir = this.source.paths().dir(); filePath = sectionDir ? `${sectionDir}/${htmlFormatBaseName}.html` : `${htmlFormatBaseName}.html`; subResourceBaseTarget = sectionDir || ""; break; case (0, content_1.getKindMain)("404"): const notFoundDir = this.source.paths().dir(); filePath = notFoundDir ? `${notFoundDir}/${this.baseName}.html` : `${this.baseName}.html`; subResourceBaseTarget = notFoundDir || ""; break; case (0, content_1.getKindMain)("sitemap"): const sitemapDir = this.source.paths().dir(); filePath = sitemapDir ? `${sitemapDir}/${this.baseName}.xml` : `${this.baseName}.xml`; subResourceBaseTarget = sitemapDir || ""; break; default: filePath = `${htmlFormatBaseName}.html`; subResourceBaseTarget = ""; break; } this.target = { prefix: this.source.identity.pageLanguage(), filePath: filePath, subResourceBaseTarget: subResourceBaseTarget }; } // Create a basic MarkdownResult implementation createBasicResult() { return { bytes: () => new Uint8Array(), headers: () => [], tableOfContents: () => ({ toHTML: (startLevel, stopLevel, ordered) => "" }) }; } // Mimics Go's Outputs() method but returns single PageOutput instead of array output(page) { return { targetFileBase: () => { if (!this.target) { return "index.html"; } const filePath = this.target.filePath; const lastSlashIndex = filePath.lastIndexOf('/'); return lastSlashIndex >= 0 ? filePath.substring(lastSlashIndex + 1) : filePath; }, targetFilePath: () => this.target.filePath, targetSubResourceDir: () => this.target.subResourceBaseTarget, targetPrefix: () => this.target.prefix, content: async () => { return page.content ? page.content.RenderedContent() : ""; }, summary: async () => { // Return summary - simplified implementation return page.content ? page.content.Summary() : ""; }, tableOfContents: () => { return page.content ? page.content.toc ? page.content.toc.toHTML(1, 6, false) : "" : ""; }, result: () => { // Return a basic MarkdownResult implementation return this.createBasicResult(); }, readingTime: async () => { // Calculate reading time - simplified implementation return page.content ? page.content.ReadingTime() : 0; }, wordCount: async () => { // Calculate word count - simplified implementation return page.content ? page.content.WordCount() : 0; } }; } } exports.Output = Output; //# sourceMappingURL=pageoutput.js.map