add: import folder of md files

This commit is contained in:
quenousimporte 2024-03-12 17:06:53 +01:00
parent 83a662a09e
commit b0bc267e18
1 changed files with 43 additions and 2 deletions

45
main.js
View File

@ -215,6 +215,10 @@ var commands = [
{
hint: "Show backlinks",
action: backlinks
},
{
hint: "Import notes",
action: importnotes
}];
var snippets = [
@ -260,6 +264,43 @@ var snippets = [
insert: "x " + (new Date).toISOString().substring(0, 10) + " "
}];
function importnotes()
{
const input = document.createElement('input');
input.type = "file";
input.webkitdirectory = true;
input.addEventListener("change", () =>
{
let files = Array.from(input.files);
files.forEach(file =>
{
var title = file.name.replace(".md", "");
if (getguid(title))
{
console.warn(title + " already exists, skip import");
}
else
{
file.text().then(content =>
{
var guid = createnote(title, content);
});
}
});
});
if ('showPicker' in HTMLInputElement.prototype)
{
input.showPicker();
}
else
{
input.click();
}
}
function genguid()
{
return crypto.randomUUID();
@ -1123,10 +1164,10 @@ function gotoline(line)
}
}
function createnote(title)
function createnote(title, content)
{
var guid = genguid();
var content = defaultheaders();
content = content || defaultheaders();
var item = {
lastchanged: Date.now(),
title: title,