UNPKG

longform-markdown-splitter

Version:

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

50 lines (49 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MD_ImageDownloader_Mapping = void 0; var csv_exporter_1 = require("../csv-exporter"); var md_filesystem_1 = require("../md-filesystem"); var uuid_1 = require("uuid"); var MD_ImageDownloader_Mapping = (function () { function MD_ImageDownloader_Mapping(properties) { this.properties = properties; } MD_ImageDownloader_Mapping.prototype.perform = function (mapping_properties) { var image_url = mapping_properties.source_value; var image_target_folder = this.properties.image_target_folder; var image_hugo_path = this.properties.image_hugo_path; if (csv_exporter_1.CSV_Exporter.is_valid_url(image_url)) { var myURL = new URL(image_url); var image_name = ""; if (myURL) if (myURL.pathname.indexOf(".") > 0) { image_name = myURL.pathname.substring(myURL.pathname.lastIndexOf("/"), myURL.pathname.length); } else { image_name = image_url.substring(image_url.lastIndexOf("/") + 1) + ".jpg"; } var uuid = (0, uuid_1.v4)(); if (mapping_properties.source.hasOwnProperty(this.properties.filename_property_name)) { uuid = mapping_properties.source[this.properties.filename_property_name]; } image_target_folder = md_filesystem_1.MD_Filesystem.concat_path_filename(image_target_folder, image_name); image_hugo_path = md_filesystem_1.MD_Filesystem.concat_path_filename(image_hugo_path, image_name); console.log("Try to download from url: '".concat(image_url, "' to '").concat(image_target_folder, "'...")); if (!this.properties.simulate) { csv_exporter_1.CSV_Exporter.download_image(image_url, image_target_folder) .then(function (result) { console.log("Downloaded from url: '".concat(image_url, "' to '").concat(image_target_folder, "' with result '").concat(result, "'")); }) .catch(console.error); } } else { image_hugo_path = ""; } return image_hugo_path; }; return MD_ImageDownloader_Mapping; }()); exports.MD_ImageDownloader_Mapping = MD_ImageDownloader_Mapping;