longform-markdown-splitter
Version:
Splits and transforms markdown files from obsidian for usage in hugo.
56 lines (55 loc) • 2.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MD_Collection = void 0;
var md_filesystem_1 = require("./md-filesystem");
var uuid_1 = require("uuid");
var MD_Collection = (function () {
function MD_Collection(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("".concat(parameter.counter, " - Splitting at '").concat(this.headline, "' with weight ").concat(weight));
}
MD_Collection.prototype.add_content = function (content) {
var newline = "\n" + content;
this.file_content += newline;
};
MD_Collection.prototype.write_file = function (writePath) {
md_filesystem_1.MD_Filesystem.write_file(writePath + this.file_name, this.file_content);
};
return MD_Collection;
}());
exports.MD_Collection = MD_Collection;