UNPKG

md-curcuma

Version:

A Typescript library for transporting and converting markdown and other data.

67 lines (66 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MD_Splitter_Task = void 0; const filesystem_1 = require("../../core/filesystem"); const MD_Frontmatter_Template_1 = require("./helpers/MD_Frontmatter_Template"); const MD_Document_1 = require("./helpers/MD_Document"); const MD_Observable_Abstract_TaskBase_1 = require("./MD_Observable_Abstract_TaskBase"); class MD_Splitter_Task extends MD_Observable_Abstract_TaskBase_1.MD_Observable_Abstract_TaskBase { constructor(parameter) { super(); this.md_document = null; this.counter = 0; this.parameter = parameter; this.parameter.frontmatter_filename = parameter.frontmatter_filename.trim(); if (parameter.frontmatter_filename.length > 0 && filesystem_1.Filesystem.is_file_exist(parameter.frontmatter_filename)) { const frontmatter = new MD_Frontmatter_Template_1.MD_Frontmatter_Template(""); frontmatter.load(parameter.frontmatter_filename); } } perform(dao) { dao = super.perform(dao); this.io_meta = dao.io_meta; return dao; } transform(mdfc, index) { if (mdfc.body_array[index].indexOf(this.parameter.pattern) == 0) { this.counter = this.counter + 1; if (typeof this.parameter.limit != "undefined" && this.counter > this.parameter.limit) return mdfc; if (this.md_document !== null) { this.md_document.write_file(this.parameter.writer_props.path); } let params = { split_row: mdfc.body_array[index], cleanName: this.parameter.cleanName, weightBase: this.parameter.weightBase, url_prefix: this.parameter.url_prefix, frontmatter: this.parameter.frontmatter, useCounter: this.parameter.hasCounter, counter: this.counter, }; this.md_document = new MD_Document_1.MD_Document(params); if (this.parameter.doRemoveHeadline) mdfc.body_array.splice(index, 1); } else { if (this.md_document !== null) { this.md_document.add_content(mdfc.body_array[index]); } } if (this.md_document !== null && index == mdfc.body_array.length - 1) { this.md_document.write_file(this.parameter.writer_props.path); } super.notify_all({ from: "md-splitter-task", to: "runner", command: "do-not-io-write", dao: null, }); return mdfc; } } exports.MD_Splitter_Task = MD_Splitter_Task;