improved: download all notes as flat md files

This commit is contained in:
quenousimporte 2023-02-21 12:05:04 +01:00
parent 95193e1d93
commit 8fcab339ce
1 changed files with 15 additions and 6 deletions

21
main.js
View File

@ -329,6 +329,10 @@ var commands = [
hint: "Download current note with merged subnotes", hint: "Download current note with merged subnotes",
action: downloadnotewithsubs action: downloadnotewithsubs
}, },
{
hint: "Download all notes as flat markdown files",
action: downloadnotes
},
{ {
hint: "Download current vault", hint: "Download current vault",
action: downloadvault, action: downloadvault,
@ -978,24 +982,29 @@ function sharehtml()
function download(filename, content) function download(filename, content)
{ {
// trick: https://www.bitdegree.org/learn/javascript-download
// to improve...
var element = document.createElement('a'); var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content)); element.setAttribute('href', 'data:text/markdown;charset=utf-8,' + encodeURIComponent(content));
element.setAttribute('download', filename); element.setAttribute('download', filename);
element.style.display = 'none'; element.style.display = 'none';
document.body.appendChild(element); document.body.appendChild(element);
element.click(); element.click();
document.body.removeChild(element); document.body.removeChild(element);
element = null;
} }
function downloadnotes() function downloadnotes()
{ {
localdata var copy = localdata.slice();
.forEach(note => console.log(copy.length + " notes to download");
var id = setInterval(() =>
{ {
var note = copy.pop();
download(note.title + ".md", note.content); download(note.title + ".md", note.content);
}); if (copy.length == 0)
{
clearInterval(id);
}
}, 500);
} }
function downloadallvaults() function downloadallvaults()