UNPKG

md-curcuma

Version:

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

55 lines (54 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MD_Document = void 0; const uuid_1 = require("uuid"); const filesystem_1 = require("../../../core/filesystem"); class MD_Document { constructor(parameter) { this.headline = ""; this.url_prefix = "prefix"; this.url = ""; this.file_name = ""; this.file_content = ""; this.nr = 0; this.weight = 8011; this.date = new Date().toJSON().slice(0, 16); this.url_prefix = parameter.url_prefix; this.weight = parameter.weightBase; this.headline = parameter.split_row.replace(parameter.cleanName, "").trim(); if (this.headline.length <= 0) { this.headline = "This Headline has no Text"; } this.url = this.headline .replace(":", "-") .replace("&", "-") .replace(",", "-") .replace(" - ", "-") .replace(/ /g, "-") .toLowerCase(); this.url = this.url.replace("---", "-").replace("--", "-"); this.file_name = parameter.useCounter ? parameter.counter + "-" + this.url : (this.file_name = this.url); this.file_name = this.file_name + ".md"; var weight = this.weight + parameter.counter; var frontmatter_props = { title: this.headline, date: this.date, url: this.url, url_prefix: this.url_prefix, uuid: (0, uuid_1.v4)(), weight: weight, }; this.file_content = parameter.frontmatter.getFrontmatter(frontmatter_props); console.log(`${parameter.counter} - Splitting at '${this.headline}' with weight ${weight}`); } add_content(content) { var newline = "\n" + content; this.file_content += newline; } write_file(writePath) { filesystem_1.Filesystem.write_file_txt(writePath + this.file_name, this.file_content); } } exports.MD_Document = MD_Document;