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",
action: downloadnotewithsubs
},
{
hint: "Download all notes as flat markdown files",
action: downloadnotes
},
{
hint: "Download current vault",
action: downloadvault,
@ -978,24 +982,29 @@ function sharehtml()
function download(filename, content)
{
// trick: https://www.bitdegree.org/learn/javascript-download
// to improve...
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.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
element = null;
}
function downloadnotes()
{
localdata
.forEach(note =>
var copy = localdata.slice();
console.log(copy.length + " notes to download");
var id = setInterval(() =>
{
var note = copy.pop();
download(note.title + ".md", note.content);
});
if (copy.length == 0)
{
clearInterval(id);
}
}, 500);
}
function downloadallvaults()