clones in export are now also md/html pages with link to the primary location

This commit is contained in:
zadam 2019-09-01 16:46:36 +02:00
parent c9cc2cb4f3
commit 1e50d88166
2 changed files with 22 additions and 13 deletions

View File

@ -406,7 +406,7 @@ div.ui-tooltip {
padding: 10px; padding: 10px;
background: var(--accented-background-color); background: var(--accented-background-color);
width: 150px; width: 150px;
height: 90px; height: 85px;
line-height: 2em; line-height: 2em;
margin-right: 20px; margin-right: 20px;
border-radius: 15px; border-radius: 15px;

View File

@ -85,23 +85,29 @@ async function exportToTar(exportContext, branch, format, res) {
return; return;
} }
const baseFileName = sanitize(branch.prefix ? (branch.prefix + ' - ' + note.title) : note.title); const completeTitle = branch.prefix ? (branch.prefix + ' - ' + note.title) : note.title;
const baseFileName = sanitize(completeTitle);
const notePath = parentMeta.notePath.concat([note.noteId]);
if (note.noteId in noteIdToMeta) { if (note.noteId in noteIdToMeta) {
const fileName = getUniqueFilename(existingFileNames, baseFileName + ".clone"); const fileName = getUniqueFilename(existingFileNames, baseFileName + ".clone." + (format === 'html' ? 'html' : 'md'));
return { return {
isClone: true, isClone: true,
noteId: note.noteId, noteId: note.noteId,
notePath: notePath,
title: note.title,
prefix: branch.prefix, prefix: branch.prefix,
dataFileName: fileName dataFileName: fileName,
type: 'text', // export will have text description,
format: format
}; };
} }
const meta = { const meta = {
isClone: false, isClone: false,
noteId: note.noteId, noteId: note.noteId,
notePath: parentMeta.notePath.concat([note.noteId]), notePath: notePath,
title: note.title, title: note.title,
notePosition: branch.notePosition, notePosition: branch.notePosition,
prefix: branch.prefix, prefix: branch.prefix,
@ -181,7 +187,8 @@ async function exportToTar(exportContext, branch, format, res) {
const meta = noteIdToMeta[targetPath[targetPath.length - 1]]; const meta = noteIdToMeta[targetPath[targetPath.length - 1]];
url += meta.dataFileName; // link can target note which is only "folder-note" and as such will not have a file in an export
url += meta.dataFileName || meta.dirFileName;
return url; return url;
} }
@ -202,9 +209,7 @@ async function exportToTar(exportContext, branch, format, res) {
return content; return content;
} }
async function prepareContent(note, noteMeta) { function prepareContent(title, content, noteMeta) {
let content = await note.getContent();
if (['html', 'markdown'].includes(noteMeta.format)) { if (['html', 'markdown'].includes(noteMeta.format)) {
content = content.toString(); content = content.toString();
@ -216,7 +221,7 @@ async function exportToTar(exportContext, branch, format, res) {
content = `<html> content = `<html>
<head><meta charset="utf-8"></head> <head><meta charset="utf-8"></head>
<body> <body>
<h1>${utils.escapeHtml(note.title)}</h1> <h1>${utils.escapeHtml(title)}</h1>
${content} ${content}
</body> </body>
</html>`; </html>`;
@ -228,7 +233,7 @@ ${content}
let markdownContent = turndownService.turndown(content); let markdownContent = turndownService.turndown(content);
if (markdownContent.trim().length > 0 && !markdownContent.startsWith("# ")) { if (markdownContent.trim().length > 0 && !markdownContent.startsWith("# ")) {
markdownContent = '# ' + note.title + "\r\n" + markdownContent; markdownContent = '# ' + title + "\r\n" + markdownContent;
} }
return markdownContent; return markdownContent;
@ -243,7 +248,11 @@ ${content}
async function saveNote(noteMeta, filePathPrefix) { async function saveNote(noteMeta, filePathPrefix) {
if (noteMeta.isClone) { if (noteMeta.isClone) {
const content = "Note is present at " + notePaths[noteMeta.noteId]; const targetUrl = getTargetUrl(noteMeta.noteId, noteMeta);
let content = `<p>This is a clone of a note. Go to its <a href="${targetUrl}">primary location</a>.</p>`;
content = prepareContent(noteMeta.title, content, noteMeta);
pack.entry({name: filePathPrefix + noteMeta.dataFileName, size: content.length}, content); pack.entry({name: filePathPrefix + noteMeta.dataFileName, size: content.length}, content);
return; return;
@ -254,7 +263,7 @@ ${content}
notePaths[note.noteId] = filePathPrefix + (noteMeta.dataFileName || noteMeta.dirFileName); notePaths[note.noteId] = filePathPrefix + (noteMeta.dataFileName || noteMeta.dirFileName);
if (noteMeta.dataFileName) { if (noteMeta.dataFileName) {
const content = await prepareContent(note, noteMeta); const content = prepareContent(noteMeta.title, await note.getContent(), noteMeta);
pack.entry({name: filePathPrefix + noteMeta.dataFileName, size: content.length}, content); pack.entry({name: filePathPrefix + noteMeta.dataFileName, size: content.length}, content);
} }