markdown import

This commit is contained in:
azivner
2018-09-03 12:05:44 +02:00
parent 9bdd4437f2
commit c41b809720
2 changed files with 86 additions and 41 deletions

View File

@@ -92,10 +92,9 @@ async function exportToTar(branch, res) {
const pack = tar.pack();
const exportedNoteIds = [];
const name = await exportNoteInner(branch.branchId, '');
const name = await exportNoteInner(branch, '');
async function exportNoteInner(branchId, directory) {
const branch = await repository.getBranch(branchId);
async function exportNoteInner(branch, directory) {
const note = await branch.getNote();
const childFileName = directory + sanitize(note.title);
@@ -138,8 +137,14 @@ async function exportToTar(branch, res) {
exportedNoteIds.push(note.noteId);
for (const child of await note.getChildBranches()) {
await exportNoteInner(child.branchId, childFileName + "/");
const childBranches = await note.getChildBranches();
if (childBranches.length > 0) {
saveDirectory(childFileName);
}
for (const childBranch of childBranches) {
await exportNoteInner(childBranch, childFileName + "/");
}
return childFileName;
@@ -157,6 +162,10 @@ async function exportToTar(branch, res) {
pack.entry({name: childFileName + ".meta", size: metadataJson.length}, metadataJson);
}
function saveDirectory(childFileName) {
pack.entry({name: childFileName, type: 'directory'});
}
pack.finalize();
res.setHeader('Content-Disposition', 'file; filename="' + name + '.tar"');
@@ -187,7 +196,13 @@ async function exportToMarkdown(branch, res) {
saveDataFile(childFileName, note);
for (const childNote of await note.getChildNotes()) {
const childNotes = await note.getChildNotes();
if (childNotes.length > 0) {
saveDirectory(childFileName);
}
for (const childNote of childNotes) {
await exportNoteInner(childNote, childFileName + "/");
}
@@ -219,6 +234,10 @@ async function exportToMarkdown(branch, res) {
pack.entry({name: childFileName + ".md", size: markdown.length}, markdown);
}
function saveDirectory(childFileName) {
pack.entry({name: childFileName, type: 'directory'});
}
pack.finalize();
res.setHeader('Content-Disposition', 'file; filename="' + name + '.tar"');