From c0cd32111840b1288382bbac55667ee7ee1ef4ed Mon Sep 17 00:00:00 2001 From: Adam Coyne Date: Sat, 30 May 2020 03:09:10 -0500 Subject: [PATCH] Fix import error (#1060) * Fix access to attributes on undefined noteMeta * Remove .markdown extension from imported page titles --- src/services/import/tar.js | 2 +- src/services/import/zip.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/import/tar.js b/src/services/import/tar.js index f09c26d16..7c607d0c5 100644 --- a/src/services/import/tar.js +++ b/src/services/import/tar.js @@ -201,7 +201,7 @@ async function importTar(taskContext, fileBuffer, importRootNote) { function getTextFileWithoutExtension(filePath) { const extension = path.extname(filePath).toLowerCase(); - if (extension === '.md' || extension === '.html') { + if (extension === '.md' || extension === '.markdown' || extension === '.html') { return filePath.substr(0, filePath.length - extension.length); } else { diff --git a/src/services/import/zip.js b/src/services/import/zip.js index cb4929165..7399f96b9 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -205,7 +205,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) { function getTextFileWithoutExtension(filePath) { const extension = path.extname(filePath).toLowerCase(); - if (extension === '.md' || extension === '.html') { + if (extension === '.md' || extension === '.markdown' || extension === '.html') { return filePath.substr(0, filePath.length - extension.length); } else { @@ -318,12 +318,14 @@ async function importZip(taskContext, fileBuffer, importRootNote) { } }); - const includeNoteLinks = (noteMeta.attributes || []) - .filter(attr => attr.type === 'relation' && attr.name === 'includeNoteLink'); + if(noteMeta) { + const includeNoteLinks = (noteMeta.attributes || []) + .filter(attr => attr.type === 'relation' && attr.name === 'includeNoteLink'); - for (const link of includeNoteLinks) { - // no need to escape the regexp find string since it's a noteId which doesn't contain any special characters - content = content.replace(new RegExp(link.value, "g"), getNewNoteId(link.value)); + for (const link of includeNoteLinks) { + // no need to escape the regexp find string since it's a noteId which doesn't contain any special characters + content = content.replace(new RegExp(link.value, "g"), getNewNoteId(link.value)); + } } }