yarle-evernote-to-md
Version:
Yet Another Rope Ladder from Evernote
134 lines • 5.8 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTimeStampMoment = exports.setFileDates = exports.logTags = exports.getTags = exports.getReminderDoneTime = exports.getReminderOrder = exports.getReminderTime = exports.getLatLong = exports.getLinkToOriginal = exports.getSourceUrl = exports.getUpdateTime = exports.getCreationTime = exports.getTitle = exports.getMetadata = void 0;
const moment_1 = __importDefault(require("moment"));
const utimes_1 = require("utimes");
const yarle_1 = require("./../yarle");
const folder_utils_1 = require("./folder-utils");
const escape_string_regexp_1 = require("./escape-string-regexp");
const output_format_1 = require("./../output-format");
const getMetadata = (note, notebookName) => {
return {
createdAt: (0, exports.getCreationTime)(note),
updatedAt: (0, exports.getUpdateTime)(note),
sourceUrl: (0, exports.getSourceUrl)(note),
location: (0, exports.getLatLong)(note),
linkToOriginal: (0, exports.getLinkToOriginal)(note),
reminderTime: (0, exports.getReminderTime)(note),
reminderOrder: (0, exports.getReminderOrder)(note),
reminderDoneTime: (0, exports.getReminderDoneTime)(note),
notebookName,
};
};
exports.getMetadata = getMetadata;
const getTitle = (note) => {
return note.title ? `# ${note.title}` : '';
};
exports.getTitle = getTitle;
const getCreationTime = (note) => {
return !yarle_1.yarleOptions.skipCreationTime && note.created
? (0, moment_1.default)(note.created).format(yarle_1.yarleOptions.dateFormat)
: undefined;
};
exports.getCreationTime = getCreationTime;
const getUpdateTime = (note) => {
return !yarle_1.yarleOptions.skipUpdateTime && note.updated
? (0, moment_1.default)(note.updated).format(yarle_1.yarleOptions.dateFormat)
: undefined;
};
exports.getUpdateTime = getUpdateTime;
const getSourceUrl = (note) => {
return !yarle_1.yarleOptions.skipSourceUrl &&
note['note-attributes']
? note['note-attributes']['source-url']
: undefined;
};
exports.getSourceUrl = getSourceUrl;
const getLinkToOriginal = (note) => {
return yarle_1.yarleOptions.keepOriginalHtml ?
(0, folder_utils_1.getHtmlFileLink)(note) : undefined;
};
exports.getLinkToOriginal = getLinkToOriginal;
const getLatLong = (note) => {
return !yarle_1.yarleOptions.skipLocation &&
note['note-attributes'] &&
note['note-attributes'].longitude
? `${note['note-attributes'].latitude},${note['note-attributes'].longitude}`
: undefined;
};
exports.getLatLong = getLatLong;
const getReminderTime = (note) => {
return !yarle_1.yarleOptions.skipReminderTime &&
note['note-attributes'] &&
note['note-attributes']['reminder-time']
? (0, moment_1.default)(note['note-attributes']['reminder-time']).format(yarle_1.yarleOptions.dateFormat)
: undefined;
};
exports.getReminderTime = getReminderTime;
const getReminderOrder = (note) => {
return !yarle_1.yarleOptions.skipReminderOrder &&
note['note-attributes'] &&
note['note-attributes']['reminder-order']
? note['note-attributes']['reminder-order']
: undefined;
};
exports.getReminderOrder = getReminderOrder;
const getReminderDoneTime = (note) => {
return !yarle_1.yarleOptions.skipReminderDoneTime &&
note['note-attributes'] &&
note['note-attributes']['reminder-done-time']
? (0, moment_1.default)(note['note-attributes']['reminder-done-time']).format(yarle_1.yarleOptions.dateFormat)
: undefined;
};
exports.getReminderDoneTime = getReminderDoneTime;
/*
<reminder-order>
<reminder-time>
<reminder-done-time> */
const getTags = (note) => {
return (0, exports.logTags)(note);
};
exports.getTags = getTags;
const logTags = (note) => {
if (!yarle_1.yarleOptions.skipTags && note.tag) {
const tagArray = Array.isArray(note.tag) ? note.tag : [note.tag];
const tagOptions = yarle_1.yarleOptions.nestedTags;
const tags = tagArray.map((tag) => {
let cleanTag = tag
.toString()
.replace(/^#/, '');
if (tagOptions) {
cleanTag = cleanTag.replace(new RegExp((0, escape_string_regexp_1.escapeStringRegexp)(tagOptions.separatorInEN), 'g'), tagOptions.replaceSeparatorWith);
}
const replaceSpaceWith = (tagOptions && tagOptions.replaceSpaceWith) || '-';
cleanTag = cleanTag.replace(/ /g, replaceSpaceWith);
if (yarle_1.yarleOptions.outputFormat === output_format_1.OutputFormat.ObsidianMD)
cleanTag = cleanTag.replace(/[^\wА-Яа-я0-9_/\\-]/g, '');
return `${yarle_1.yarleOptions.useHashTags ? '#' : ''}${cleanTag}`;
});
return tags.join(' ');
}
return undefined;
};
exports.logTags = logTags;
const setFileDates = (path, created, updated) => {
const createdTime = created ? Math.max(0, (0, moment_1.default)(created).valueOf()) : 0;
const updatedTime = updated ? Math.max(0, (0, moment_1.default)(updated).valueOf()) : createdTime;
(0, utimes_1.utimesSync)(path, {
btime: createdTime,
mtime: updatedTime,
atime: updatedTime
});
};
exports.setFileDates = setFileDates;
const getTimeStampMoment = (resource) => {
return resource['resource-attributes'] &&
resource['resource-attributes']['timestamp']
? (0, moment_1.default)(resource['resource-attributes']['timestamp'])
: (0, moment_1.default)();
};
exports.getTimeStampMoment = getTimeStampMoment;
//# sourceMappingURL=content-utils.js.map