UNPKG

@mdfriday/foundry

Version:

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

131 lines 4.3 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Taxonomy = void 0; const pagetrees_1 = require("./pagetrees"); const fileinfo_1 = require("../vo/fileinfo"); const pagesource_1 = require("./pagesource"); const path = __importStar(require("path")); const filepath = __importStar(require("path")); class Taxonomy { constructor(views, fsSvc) { this.views = views; this.fsSvc = fsSvc; } /** * Assemble - exact replica of Go's Assemble method */ async assemble(pages, pb) { for (const viewName of this.views) { const key = this.pluralTreeKey(viewName.plural()); const v = pages.get(key); if (!v) { const fmi = this.fsSvc.newFileMetaInfo(key + "/_index.md"); const f = (0, fileinfo_1.newFileInfo)(fmi); const ps = (0, pagesource_1.newPageSource)(f); const p = await pb.withSource(ps).kindBuild(); pages.insertIntoValuesDimension(key, (0, pagetrees_1.newPageTreesNode)(p)); } } } /** * IsTaxonomyPath - exact replica of Go's IsTaxonomyPath method */ isTaxonomyPath(p) { const ta = this.getTaxonomy(p); if (!ta) { return false; } return p === path.join(this.pluralTreeKey(ta.plural()), "_index.md"); } /** * PluralTreeKey - exact replica of Go's PluralTreeKey method */ pluralTreeKey(plural) { return cleanTreeKey(plural); } /** * GetTaxonomy - exact replica of Go's getTaxonomy method */ getTaxonomy(s) { for (const n of this.views) { if (s.startsWith(this.pluralTreeKey(n.plural()))) { return n; } } return null; } /** * IsZero - exact replica of Go's IsZero method */ isZero(v) { if (!v) { return true; } return v.singular() === ""; } } exports.Taxonomy = Taxonomy; /** * Clean tree key - exact replica of Go's cleanTreeKey function * The home page is represented with the zero string. * All other keys starts with a leading slash. No trailing slash. * Slashes are Unix-style. */ function cleanTreeKey(...elem) { let s = ''; if (elem.length > 0) { s = elem[0]; if (elem.length > 1) { s = path.join(...elem); } } s = s.replace(/^[\.\/ \s]+|[\.\/ \s]+$/g, ''); // trimCutsetDotSlashSpace equivalent s = filepath.posix.normalize(s.toLowerCase().replace(/[^\w\-_\/]/g, '')); // Sanitize equivalent if (s === '' || s === '/') { return ''; } if (s[0] !== '/') { s = '/' + s; } return s; } /** * Trim cutset function - equivalent to Go's trimCutsetDotSlashSpace */ function trimCutsetDotSlashSpace(r) { return r === '.' || r === '/' || /\s/.test(r); } //# sourceMappingURL=taxonomy.js.map