UNPKG

@mdfriday/foundry

Version:

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

101 lines 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Taxonomy = void 0; exports.newTaxonomy = newTaxonomy; const taxonomy_1 = require("../../../domain/config/vo/taxonomy"); /** * Taxonomy entity holds taxonomy configuration */ class Taxonomy { constructor(taxonomies) { this.taxonomies = taxonomies; this.views = []; this.viewsByTreeKey = {}; this.setupViews(); } /** * Get taxonomy views */ getViews() { return [...this.views]; } /** * Get taxonomies configuration */ getTaxonomies() { return { ...this.taxonomies }; } /** * Get view by tree key */ getViewByTreeKey(treeKey) { return this.viewsByTreeKey[treeKey]; } /** * Check if taxonomy exists */ hasTaxonomy(singular) { return Object.prototype.hasOwnProperty.call(this.taxonomies, singular); } /** * Get plural form of taxonomy */ getPluralForm(singular) { return this.taxonomies[singular]; } /** * Get singular form from plural */ getSingularForm(plural) { for (const [singular, pluralForm] of Object.entries(this.taxonomies)) { if (pluralForm === plural) { return singular; } } return undefined; } /** * Get all singular forms */ getSingularForms() { return Object.keys(this.taxonomies); } /** * Get all plural forms */ getPluralForms() { return Object.values(this.taxonomies); } /** * Setup taxonomy views */ setupViews() { this.views = (0, taxonomy_1.setupTaxonomyViews)(this.taxonomies); // Create viewsByTreeKey map this.viewsByTreeKey = {}; for (const view of this.views) { this.viewsByTreeKey[view.pluralTreeKey] = view; } } /** * Get view count */ getViewCount() { return this.views.length; } /** * Check if taxonomies are empty */ isEmpty() { return Object.keys(this.taxonomies).length === 0; } } exports.Taxonomy = Taxonomy; /** * Create a new Taxonomy instance from provider data */ function newTaxonomy(data) { const taxonomies = (0, taxonomy_1.decodeTaxonomyConfig)(data); return new Taxonomy(taxonomies); } //# sourceMappingURL=taxonomy.js.map