imported notes from tar now have correct links even without meta file

This commit is contained in:
zadam
2019-08-31 22:39:25 +02:00
parent 576a07bcb7
commit fe6f19e611
3 changed files with 81 additions and 29 deletions

View File

@@ -187,16 +187,16 @@ async function exportToTar(exportContext, branch, format, res) {
}
function findLinks(content, noteMeta) {
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9]+)\/[^"]*"/g, (_, targetNoteId) => {
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9]+)\/[^"]*"/g, (match, targetNoteId) => {
const url = getTargetUrl(targetNoteId, noteMeta);
return `src="${url}"`;
return url ? `src="${encodeURIComponent(url)}"` : match;
});
content = content.replace(/href="[^"]*#root[a-zA-Z0-9\/]*\/([a-zA-Z0-9]+)\/?"/g, (_, targetNoteId) => {
content = content.replace(/href="[^"]*#root[a-zA-Z0-9\/]*\/([a-zA-Z0-9]+)\/?"/g, (match, targetNoteId) => {
const url = getTargetUrl(targetNoteId, noteMeta);
return `href="${url}"`;
return url ? `href="${encodeURIComponent(url)}"` : match;
});
return content;