trilium/static/js/convert2html.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-09-18 09:17:04 +08:00
function convertNoteToHtml(noteId, failedNotes) {
$.ajax({
2017-09-30 22:05:12 +08:00
url: baseApiUrl + 'notes/' + noteId,
2017-09-18 09:17:04 +08:00
type: 'GET',
async: false,
success: function (note) {
const noteNode = getNodeByKey(noteId);
if (noteNode.data.is_clone) {
// we shouldn't process notes twice
return;
}
note.formatting = [];
for (const link of note.links) {
delete link.type;
}
$.ajax({
2017-09-30 22:05:12 +08:00
url: baseApiUrl + 'notes/' + noteId,
2017-09-18 09:17:04 +08:00
type: 'PUT',
data: JSON.stringify(note),
contentType: "application/json",
async: false,
success: function () {
console.log("Note " + noteId + " converted.")
},
error: function () {
console.log("Note " + noteId + " failed when writing");
failedNotes.push(noteId);
}
});
},
error: function () {
console.log("Note " + noteId + " failed when reading");
failedNotes.push(noteId);
}
});
}
2017-09-17 23:20:33 +08:00
function convertAll2Html() {
const failedNotes = [];
let counter = 1;
for (const noteId of globalAllNoteIds) {
console.log('Converting ' + counter + "/" + globalAllNoteIds.length);
counter++;
2017-09-18 09:17:04 +08:00
convertNoteToHtml(noteId, failedNotes);
2017-09-17 23:20:33 +08:00
}
console.log("Failed notes: ", failedNotes);
}