UNPKG

@mdfriday/foundry

Version:

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

249 lines 7.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PageTrees = exports.PageTreesNode = exports.WeightedTermTreeNode = void 0; exports.newPageTreesNode = newPageTreesNode; const doctree_1 = require("../../../../pkg/doctree"); const shifterpage_1 = require("./shifterpage"); const shifterpagesource_1 = require("./shifterpagesource"); /** * WeightPage - weighted page with ordinal */ class WeightPage { constructor(ordinalWeightPage, page) { this.ordinalWeightPageInstance = ordinalWeightPage; this.page = page; } Page() { return this.page; } Owner() { return this.ordinalWeightPageInstance.page; } Weight() { return this.ordinalWeightPageInstance.Weight(); } Ordinal() { return this.ordinalWeightPageInstance.Ordinal(); } } /** * OrdinalWeightPage - page with ordinal and weight */ class OrdinalWeightPage { constructor(ordinal, weight, page) { this.ordinal = ordinal; this.weight = weight; this.page = page; } Weight() { return this.weight; } Ordinal() { return this.ordinal; } // Delegate all Page methods to the embedded page kind() { return this.page.kind(); } name() { return this.page.name(); } title() { return this.page.title(); } } /** * WeightedTermTreeNode - tree node for weighted terms */ class WeightedTermTreeNode { constructor(pageTreesNode, term) { this.pageTreesNodeInstance = pageTreesNode; this.term = term; } // Delegate PageTreesNode methods getPage() { return this.pageTreesNodeInstance.getPage(); } getPages() { return this.pageTreesNodeInstance.getPages(); } getResource() { return this.pageTreesNodeInstance.getResource(); } isEmpty() { return this.pageTreesNodeInstance.isEmpty(); } shift(languageIndex, exact) { return this.pageTreesNodeInstance.shift(languageIndex, exact); } } exports.WeightedTermTreeNode = WeightedTermTreeNode; class PageTreesNode { constructor() { this.nodes = new Map(); } setNode(key, value) { this.nodes.set(key, value); } merge(newNode) { // Create a map to track existing keys by their IDs const existingKeys = new Map(); for (const key of this.nodes.keys()) { existingKeys.set(key.pageLanguage(), key); } // Update or add entries from the new map for (const [newKey, newValue] of newNode.nodes.entries()) { const oldKey = existingKeys.get(newKey.pageLanguage()); if (oldKey) { // Replace the old value with the new value this.nodes.set(oldKey, newValue); } else { // Add the new key-value pair to the old map this.nodes.set(newKey, newValue); } } return this; } mergeWithLang(newNode, languageIndex) { // Create a map to track existing keys by their IDs const existingKeys = new Map(); for (const key of this.nodes.keys()) { existingKeys.set(key.pageLanguage(), key); } // Update or add entries from the new map for (const [newKey, newValue] of newNode.nodes.entries()) { const oldKey = existingKeys.get(newKey.pageLanguage()); if (oldKey) { const existingPageSource = this.nodes.get(oldKey); if (existingPageSource && existingPageSource.pageIdentity().pageLanguageIndex() === languageIndex) { this.remove(oldKey); } } this.nodes.set(newKey, newValue); } return this; } remove(k) { const v = this.nodes.get(k); if (!v) { return false; } // Mark stale - equivalent to stale.MarkStale(v) in Go this.markStale(v); this.nodes.delete(k); return true; } delete(languageIndex) { for (const [k, v] of this.nodes.entries()) { if (v.pageIdentity().pageLanguageIndex() === languageIndex) { return this.remove(k); } } return false; } isEmpty() { return this.nodes.size === 0; } shift(languageIndex, exact) { let firstV = null; for (const [k, v] of this.nodes.entries()) { if (firstV === null) { firstV = v; } if (v.pageIdentity().pageLanguageIndex() === languageIndex) { return [newPageTreesNode(v), true]; } } if (firstV !== null && !exact) { return [newPageTreesNode(firstV), false]; } return [null, false]; } getPage() { for (const v of this.nodes.values()) { // Check if v is actually a Page object (has kind() method) if (v && typeof v.kind === 'function') { return [v, true]; } } return [null, false]; } getPages() { const pages = []; for (const v of this.nodes.values()) { // Only add objects that are actually Page objects if (v && typeof v.kind === 'function') { pages.push(v); } } return pages; } getResource() { for (const v of this.nodes.values()) { return [v, true]; } return [null, false]; } // Helper method to mark resources as stale markStale(v) { // Equivalent to Go's stale.MarkStale(v) // In TypeScript, this would mark the resource as stale for cache invalidation if ('staleVersions' in v && typeof v.staleVersions === 'function') { // The staler interface method would be called here } } } exports.PageTreesNode = PageTreesNode; class PageTrees { constructor() { this.treePages = new doctree_1.NodeShiftTree({ shifter: new shifterpage_1.PageShifter() }); this.treeResources = new doctree_1.NodeShiftTree({ shifter: new shifterpagesource_1.SourceShifter() }); this.treeTaxonomyEntries = doctree_1.TreeShiftTree.newTreeShiftTree(0, 10); // 10 language slots // Initialize arrays as empty - will be populated by createMutableTrees this.treePagesResources = new doctree_1.WalkableTrees([]); this.resourceTrees = new doctree_1.MutableTrees([]); this.treePagesResources = new doctree_1.WalkableTrees([ this.treePages, this.treeResources, ]); this.resourceTrees = new doctree_1.MutableTrees([ this.treeResources, ]); } createMutableTrees() { this.treePagesResources = new doctree_1.WalkableTrees([ this.treePages, this.treeResources, ]); this.resourceTrees = new doctree_1.MutableTrees([ this.treeResources, ]); } // Getter properties to match Golang struct embedding get TreePages() { return this.treePages; } get TreeResources() { return this.treeResources; } get TreePagesResources() { return this.treePagesResources; } get TreeTaxonomyEntries() { return this.treeTaxonomyEntries; } get ResourceTrees() { return this.resourceTrees; } } exports.PageTrees = PageTrees; /** * Factory function to create new PageTreesNode */ function newPageTreesNode(ps) { const n = new PageTreesNode(); if (ps) { n.setNode(ps.pageIdentity(), ps); } return n; } //# sourceMappingURL=pagetrees.js.map