Merge branch 'feat/upcoming'

This commit is contained in:
quenousimporte 2023-09-27 12:14:29 +02:00
commit 373ac8a9b6
1 changed files with 46 additions and 0 deletions

46
main.js
View File

@ -360,6 +360,10 @@ var commands = [
{
hint: "Decrypt note",
action: decryptnote
},
{
hint: "Show upcoming events",
action: showupcomingevents
}];
var snippets = [
@ -974,6 +978,48 @@ function changesetting()
});
}
function showupcomingevents()
{
var note = getnote("events.json");
if (note)
{
var upcomingnote = getorcreate("Upcoming events", "---\ntags: preview\n---\n\n");
var events = JSON.parse(note.content);
var sorted = {};
events.forEach(event =>
{
var date = new Date(event.DTSTART);
if (date >= new Date)
{
event.readabledate = date.toLocaleDateString('fr-FR', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
var month = event.readabledate.split(" ")[2];
var year = event.readabledate.split(" ")[3];
sorted[year] = sorted[year] || {};
sorted[year][month] = sorted[year][month] || [];
sorted[year][month].push(event);
}
});
upcomingnote.content = "";
for (var year in sorted)
{
upcomingnote.content += "# " + year + "\n";
for (var month in sorted[year])
{
upcomingnote.content += "## " + month.charAt(0).toUpperCase() + month.slice(1) + "\n";
for (var i in sorted[year][month])
{
var event = sorted[year][month][i];
upcomingnote.content += event.readabledate.split(" ")[0] + " " + event.readabledate.split(" ")[1] + ": " + event.SUMMARY + "\n";
}
}
}
bindfile(upcomingnote);
togglepreview();
}
}
function decryptnote()
{
decryptstring(md.value)