mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
OPML v2 export
This commit is contained in:
parent
6fd8e73150
commit
a7fce33750
@ -39,6 +39,8 @@ async function showDialog(defaultType) {
|
|||||||
throw new Error("Unrecognized type " + defaultType);
|
throw new Error("Unrecognized type " + defaultType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#opml-v2").prop("checked", true); // setting default
|
||||||
|
|
||||||
glob.activeDialog = $dialog;
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
$dialog.modal();
|
$dialog.modal();
|
||||||
|
@ -38,7 +38,7 @@ class ExportContext {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// must remaing static
|
// must remaing non-static
|
||||||
async reportError(message) {
|
async reportError(message) {
|
||||||
await messagingService.sendMessageToAllClients({
|
await messagingService.sendMessageToAllClients({
|
||||||
type: 'export-error',
|
type: 'export-error',
|
||||||
|
@ -46,7 +46,7 @@ class ImportContext {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// must remaing static
|
// must remaing non-static
|
||||||
async reportError(message) {
|
async reportError(message) {
|
||||||
await messagingService.sendMessageToAllClients({
|
await messagingService.sendMessageToAllClients({
|
||||||
type: 'import-error',
|
type: 'import-error',
|
||||||
|
@ -4,7 +4,11 @@ const repository = require("../repository");
|
|||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
|
||||||
async function exportToOpml(exportContext, branch, version, res) {
|
async function exportToOpml(exportContext, branch, version, res) {
|
||||||
console.log("EXPORTING VERSION ", version);
|
if (!['1.0', '2.0'].includes(version)) {
|
||||||
|
throw new Error("Unrecognized OPML version " + version);
|
||||||
|
}
|
||||||
|
|
||||||
|
const opmlVersion = parseInt(version);
|
||||||
|
|
||||||
const note = await branch.getNote();
|
const note = await branch.getNote();
|
||||||
|
|
||||||
@ -18,10 +22,21 @@ async function exportToOpml(exportContext, branch, version, res) {
|
|||||||
|
|
||||||
const title = (branch.prefix ? (branch.prefix + ' - ') : '') + note.title;
|
const title = (branch.prefix ? (branch.prefix + ' - ') : '') + note.title;
|
||||||
|
|
||||||
const preparedTitle = prepareText(title);
|
if (opmlVersion === 1) {
|
||||||
|
const preparedTitle = escapeXmlAttribute(title);
|
||||||
const preparedContent = prepareText(await note.getContent());
|
const preparedContent = prepareText(await note.getContent());
|
||||||
|
|
||||||
res.write(`<outline title="${preparedTitle}" text="${preparedContent}">\n`);
|
res.write(`<outline title="${preparedTitle}" text="${preparedContent}">\n`);
|
||||||
|
}
|
||||||
|
else if (opmlVersion === 2) {
|
||||||
|
const preparedTitle = escapeXmlAttribute(title);
|
||||||
|
const preparedContent = escapeXmlAttribute(await note.getContent());
|
||||||
|
|
||||||
|
res.write(`<outline text="${preparedTitle}" _note="${preparedContent}">\n`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error("Unrecognized OPML version " + opmlVersion);
|
||||||
|
}
|
||||||
|
|
||||||
exportContext.increaseProgressCount();
|
exportContext.increaseProgressCount();
|
||||||
|
|
||||||
@ -32,6 +47,7 @@ async function exportToOpml(exportContext, branch, version, res) {
|
|||||||
res.write('</outline>');
|
res.write('</outline>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const filename = (branch.prefix ? (branch.prefix + ' - ') : '') + note.title + ".opml";
|
const filename = (branch.prefix ? (branch.prefix + ' - ') : '') + note.title + ".opml";
|
||||||
|
|
||||||
res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
|
res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user