add: import folder of md files
This commit is contained in:
parent
83a662a09e
commit
b0bc267e18
45
main.js
45
main.js
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue