added: backlinks in internal links list

added: customer title in list
fixed: unload current note after deletion
added: share note as html file
This commit is contained in:
quenousimporte 2023-01-27 09:22:09 +01:00
parent c27f5cf61e
commit b8293768b5
1 changed files with 35 additions and 16 deletions

51
main.js
View File

@ -128,11 +128,11 @@ var commands = [
hint: "Share note", hint: "Share note",
action: share, action: share,
allowunsaved: true allowunsaved: true
}/*, },
{ {
hint: "Share note (html)", hint: "Share note (html)",
action: sharehtml action: sharehtml
}*/, },
{ {
shortcut: "ctrl+n", shortcut: "ctrl+n",
hint: "New note", hint: "New note",
@ -256,7 +256,7 @@ var commands = [
allowunsaved: true allowunsaved: true
}, },
{ {
hint: "Internal links", hint: "Internal and back links",
action: showinternallinks action: showinternallinks
}, },
{ {
@ -333,7 +333,7 @@ function showinfo()
"current note queries: " + stat.cur.q, "current note queries: " + stat.cur.q,
"session start: " + stat.ses.t, "session start: " + stat.ses.t,
"session queries: " + stat.ses.q "session queries: " + stat.ses.q
]); ], "Note info");
} }
function loadtheme(theme) function loadtheme(theme)
@ -391,10 +391,14 @@ function switchvault()
function showinternallinks() function showinternallinks()
{ {
searchinlist( var backlinks = localdata
getnotecontent() .filter(n => n.content.indexOf("[[" + currentnote.title + "]]") != -1)
.match(/\[\[([^\]]*)\]\]/g || []) .map(n => n.title);
.map(l => l.replace("[[", "").replace("]]", "")))
var internal = getnotecontent().match(/\[\[([^\]]*)\]\]/g) || [];
internal = internal.map(l => l.replace("[[", "").replace("]]", ""));
searchinlist(internal.concat(backlinks))
.then(loadnote); .then(loadnote);
} }
@ -409,7 +413,7 @@ function showoutline()
{ {
line = line line = line
.replace("# ", "") .replace("# ", "")
.replace(/#/g, "\xa0\xa0\xa0\xa0"); .replace(/#/g, "\xa0".repeat(4));
outline[line] = pos; outline[line] = pos;
} }
}); });
@ -512,14 +516,14 @@ function editsettings()
}); });
} }
function showtemporaryinfo(data) function showtemporaryinfo(data, title)
{ {
if (typeof data == "string") if (typeof data == "string")
{ {
data = new Array(data); data = new Array(data);
} }
filter.placeholder = "Info"; filter.placeholder = title || "Info";
searchinlist(data) searchinlist(data)
.then(() => .then(() =>
{ {
@ -601,13 +605,13 @@ function gettags(note)
return []; return [];
} }
function share(html) function share()
{ {
if (navigator.share) if (navigator.share)
{ {
navigator.share( navigator.share(
{ {
text: html ? md2html(getnotecontent()) : getnotecontent(), text: getnotecontent(),
title: currentnote.title title: currentnote.title
}); });
} }
@ -615,7 +619,20 @@ function share(html)
function sharehtml() function sharehtml()
{ {
share(true); if (navigator.share)
{
var file = new File(['<html><body>' + md2html(getnotecontent()) + '</body></html>'],
currentnote.title + ".html",
{
type: "text/html",
});
navigator.share(
{
title: currentnote.title,
files: [file]
});
}
} }
function download(filename, content) function download(filename, content)
@ -661,7 +678,7 @@ function remotecallfailed(error)
if (error) if (error)
{ {
console.warn(error); console.warn(error);
showtemporaryinfo(error); showtemporaryinfo(error, "Error");
} }
} }
@ -1554,9 +1571,11 @@ function deletenote()
{ {
var trash = JSON.parse(window.localStorage.getItem("trash")) || []; var trash = JSON.parse(window.localStorage.getItem("trash")) || [];
trash.push(currentnote); trash.push(currentnote);
loadlast();
window.localStorage.setItem("trash", JSON.stringify(trash)); window.localStorage.setItem("trash", JSON.stringify(trash));
localdata = localdata.filter(n => n != currentnote); localdata = localdata.filter(n => n != currentnote);
loadlast();
datachanged(); datachanged();
} }
} }