Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
UI for export of OPML v2, WIP
zadam6fd8e7315006
diff --git a/src/public/javascripts/dialogs/export.js b/src/public/javascripts/dialogs/export.jsindex abb408009e..a2d5faa8bf 100644--- a/src/public/javascripts/dialogs/export.js+++ b/src/public/javascripts/dialogs/export.js@@ -15,6 +15,7 @@ const $singleType = $("#export-type-single");const $exportProgressWrapper = $("#export-progress-count-wrapper");const $exportProgressCount = $("#export-progress-count");const $exportButton = $("#export-button");+const $opmlVersions = $("#opml-versions");let exportId = '';@@ -27,6 +28,9 @@ async function showDialog(defaultType) {if (defaultType === 'subtree') {$subtreeType.prop("checked", true).change();++ // to show/hide OPML versions+ $("input[name=export-subtree-format]:checked").change();}else if (defaultType === 'single') {$singleType.prop("checked", true).change();@@ -61,17 +65,19 @@ $form.submit(() => {? $("input[name=export-subtree-format]:checked").val(): $("input[name=export-single-format]:checked").val();+ const exportVersion = exportFormat === 'opml' ? $dialog.find("input[name='opml-version']:checked").val() : "1.0";+const currentNode = treeService.getCurrentNode();- exportBranch(currentNode.data.branchId, exportType, exportFormat);+ exportBranch(currentNode.data.branchId, exportType, exportFormat, exportVersion);return false;});-function exportBranch(branchId, type, format) {+function exportBranch(branchId, type, format, version) {exportId = utils.randomString(10);- const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}/${exportId}?protectedSessionId=` + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());+ const url = utils.getHost() + `/api/notes/${branchId}/export/${type}/${format}/${version}/${exportId}?protectedSessionId=` + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());utils.download(url);}@@ -95,6 +101,15 @@ $('input[name=export-type]').change(function () {}});+$('input[name=export-subtree-format]').change(function () {+ if (this.value === 'opml') {+ $opmlVersions.slideDown();+ }+ else {+ $opmlVersions.slideUp();+ }+});+messagingService.subscribeToMessages(async message => {if (message.type === 'export-error') {infoService.showError(message.message);diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.cssindex f862925381..d6705dd89a 100644--- a/src/public/stylesheets/style.css+++ b/src/public/stylesheets/style.css@@ -813,6 +813,11 @@ div[data-notify="container"] {display: none;}+#export-form #opml-versions {+ padding-left: 60px;+ display: none;+}+#export-form .form-check-label {padding: 2px;}diff --git a/src/routes/api/export.js b/src/routes/api/export.jsindex 5215872673..f042be2d7e 100644--- a/src/routes/api/export.js+++ b/src/routes/api/export.js@@ -48,7 +48,7 @@ class ExportContext {}async function exportBranch(req, res) {- const {branchId, type, format, exportId} = req.params;+ const {branchId, type, format, version, exportId} = req.params;const branch = await repository.getBranch(branchId);const exportContext = new ExportContext(exportId);@@ -61,7 +61,7 @@ async function exportBranch(req, res) {await singleExportService.exportSingleNote(exportContext, branch, format, res);}else if (format === 'opml') {- await opmlExportService.exportToOpml(exportContext, branch, res);+ await opmlExportService.exportToOpml(exportContext, branch, version, res);}else {return [404, "Unrecognized export format " + format];diff --git a/src/routes/routes.js b/src/routes/routes.jsindex 87b494038c..bd0ce69863 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -128,7 +128,7 @@ function register(app) {apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent);apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter);- route(GET, '/api/notes/:branchId/export/:type/:format/:exportId', [auth.checkApiAuthOrElectron], exportRoute.exportBranch);+ route(GET, '/api/notes/:branchId/export/:type/:format/:version/:exportId', [auth.checkApiAuthOrElectron], exportRoute.exportBranch);route(POST, '/api/notes/:parentNoteId/import/:importId/safe/:safeImport', [auth.checkApiAuthOrElectron, uploadMiddleware], importRoute.importToBranch, apiResultHandler);route(POST, '/api/notes/:parentNoteId/upload', [auth.checkApiAuthOrElectron, uploadMiddleware],diff --git a/src/services/export/opml.js b/src/services/export/opml.jsindex 26160e0cc7..5d8c7604bf 100644--- a/src/services/export/opml.js+++ b/src/services/export/opml.js@@ -3,7 +3,9 @@const repository = require("../repository");const utils = require('../utils');-async function exportToOpml(exportContext, branch, res) {+async function exportToOpml(exportContext, branch, version, res) {+ console.log("EXPORTING VERSION ", version);+const note = await branch.getNote();async function exportNoteInner(branchId) {diff --git a/src/views/dialogs/export.ejs b/src/views/dialogs/export.ejsindex 30c9337560..13bf68ad3d 100644--- a/src/views/dialogs/export.ejs+++ b/src/views/dialogs/export.ejs@@ -40,6 +40,18 @@OPML - outliner interchange format for text only. Formatting, images and files are not included.</label></div>++ <div id="opml-versions">+ <div class="form-check">+ <input class="form-check-input" type="radio" name="opml-version" id="opml-v1" value="1.0">+ <label class="form-check-label" for="opml-v1">OPML v1.0 - plain text only</label>+ </div>++ <div class="form-check">+ <input class="form-check-input" type="radio" name="opml-version" id="opml-v2" value="2.0">+ <label class="form-check-label" for="opml-v2">OMPL v2.0 - allows also HTML</label>+ </div>+ </div></div><div class="form-check">