yarle-evernote-to-md
Version:
Yet Another Rope Ladder from Evernote
208 lines • 8.76 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.getLinkToOriginal = exports.getApplicationData = exports.getContentClass = exports.getPlaceName = exports.getSourceApplication = exports.getSourceUrl = exports.getSource = exports.getAuthor = exports.getAltitude = exports.getLatLong = exports.getSubjectDate = 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 get_title_1 = require("./get-title");
const getMetadata = (note, notebookName) => {
return {
createdAt: (0, exports.getCreationTime)(note),
updatedAt: (0, exports.getUpdateTime)(note),
subjectDate: (0, exports.getSubjectDate)(note),
author: (0, exports.getAuthor)(note),
source: (0, exports.getSource)(note),
sourceUrl: (0, exports.getSourceUrl)(note),
sourceApplication: (0, exports.getSourceApplication)(note),
location: (0, exports.getLatLong)(note),
altitude: (0, exports.getAltitude)(note),
placeName: (0, exports.getPlaceName)(note),
contentClass: (0, exports.getContentClass)(note),
applicationData: (0, exports.getApplicationData)(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;
//////// Note Attributes
const getSubjectDate = (note) => {
return !yarle_1.yarleOptions.skipSubjectDate &&
note['note-attributes']
? note['note-attributes']['subject-date']
: undefined;
};
exports.getSubjectDate = getSubjectDate;
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 getAltitude = (note) => {
return !yarle_1.yarleOptions.skipAltitude &&
note['note-attributes']
? note['note-attributes']['altitude']
: undefined;
};
exports.getAltitude = getAltitude;
const getAuthor = (note) => {
return !yarle_1.yarleOptions.skipAuthor &&
note['note-attributes']
? note['note-attributes']['author']
: undefined;
};
exports.getAuthor = getAuthor;
const getSource = (note) => {
return !yarle_1.yarleOptions.skipSource &&
note['note-attributes']
? note['note-attributes']['source']
: undefined;
};
exports.getSource = getSource;
const getSourceUrl = (note) => {
return !yarle_1.yarleOptions.skipSourceUrl &&
note['note-attributes']
? note['note-attributes']['source-url']
: undefined;
};
exports.getSourceUrl = getSourceUrl;
const getSourceApplication = (note) => {
return !yarle_1.yarleOptions.skipSourceApplication &&
note['note-attributes']
? note['note-attributes']['source-application']
: undefined;
};
exports.getSourceApplication = getSourceApplication;
const getPlaceName = (note) => {
return !yarle_1.yarleOptions.skipPlaceName &&
note['note-attributes']
? note['note-attributes']['place-name']
: undefined;
};
exports.getPlaceName = getPlaceName;
const getContentClass = (note) => {
return !yarle_1.yarleOptions.skipContentClass &&
note['note-attributes']
? note['note-attributes']['content-class']
: undefined;
};
exports.getContentClass = getContentClass;
const getApplicationData = (note) => {
if (!yarle_1.yarleOptions.skipApplicationData && note['note-attributes'] && note['note-attributes']['application-data']) {
const appdataArray = Array.isArray(note['note-attributes']['application-data'])
? note['note-attributes']['application-data']
: [note['note-attributes']['application-data']];
const appdata = appdataArray.map((enexNode) => {
return ` - ${enexNode.$attrs.key}: ${enexNode.$text}`;
});
return '\n' + appdata.join('\n');
}
else {
return undefined;
}
};
exports.getApplicationData = getApplicationData;
const getLinkToOriginal = (note) => {
return yarle_1.yarleOptions.keepOriginalHtml ?
(0, folder_utils_1.getHtmlFileLink)(note) : undefined;
};
exports.getLinkToOriginal = getLinkToOriginal;
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(/^#/, '');
cleanTag = (0, get_title_1.performRegexpOnTag)(yarle_1.yarleOptions, cleanTag);
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.removeUnicodeCharsFromTags)
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