UNPKG

longform-markdown-splitter

Version:

Splits and transforms markdown files from obsidian for usage in hugo.

85 lines (84 loc) 4.11 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MD_Frontmatter_Transformer = void 0; var md_filesystem_1 = require("../md-filesystem"); var md_transformer_1 = require("../md-transformer"); var md_frontmatter_1 = require("../md-frontmatter"); var md_mapping_1 = require("../md-mapping"); var MD_Frontmatter_Transformer = (function (_super) { __extends(MD_Frontmatter_Transformer, _super); function MD_Frontmatter_Transformer(parameter) { var _this = _super.call(this) || this; _this.parameter = parameter; _this.parameter.frontmatter_filename = parameter.frontmatter_filename.trim(); if (parameter.frontmatter_filename.length > 0 && md_filesystem_1.MD_Filesystem.is_file_exist(parameter.frontmatter_filename)) { console.log("before: ".concat(parameter.frontmatter)); var frontmatter = new md_frontmatter_1.MD_Frontmatter_Template(""); frontmatter.load(parameter.frontmatter_filename); parameter.frontmatter = frontmatter; console.log("after: ".concat(parameter.frontmatter)); } else { console.log("file not found: ".concat(parameter.frontmatter_filename)); console.log(parameter.frontmatter); } return _this; } MD_Frontmatter_Transformer.prototype.add_observer = function (observer) { this.observer_subject.add_observer(observer); }; MD_Frontmatter_Transformer.prototype.set_job_parameter = function (job_paramter) { _super.prototype.set_job_parameter.call(this, job_paramter); }; MD_Frontmatter_Transformer.prototype.transform = function (file_content, index) { if (index === 0) { file_content.frontmatter; file_content.frontmatter_attributes; var template_content = md_filesystem_1.MD_Filesystem.split_frontmatter_body(this.parameter.frontmatter.get_template_string()); template_content.frontmatter; template_content.frontmatter_attributes; console.log("Frontmatter-Source:", file_content.frontmatter_attributes, ", Frontmatter-Target:", template_content.frontmatter_attributes); var fm_old = file_content.frontmatter_attributes; var fm_new = template_content.frontmatter_attributes; for (var prop in fm_old) { if (fm_new.hasOwnProperty(prop)) { fm_new[prop] = fm_old[prop]; } } var mapper = new md_mapping_1.MD_Mapper(); mapper.addMappings(this.parameter.mappings); mapper.do_mappings(file_content.frontmatter_attributes, fm_new); file_content.frontmatter_attributes = __assign({}, fm_new); } return file_content; }; return MD_Frontmatter_Transformer; }(md_transformer_1.MD_Transformer_AbstractBase)); exports.MD_Frontmatter_Transformer = MD_Frontmatter_Transformer;