%% NOTE: Remove code fences. They were added for gist rendering purposes. %%
<%*
dv = app.plugins.plugins.dataview.api;
function lucky() {
const threshold = dv.date('now') - dv.duration('14 days');
const list = dv.pages().where(p => {
if (p["se-last-reviewed"]) {
const lastReviewed = p["se-last-reviewed"].toString().slice(0, 10);
return dv.date(lastReviewed) < threshold;
} else {
return false;
}
});
const file = list[Math.floor(Math.random() * list.length)].file;
app.workspace.getLeaf(true).openFile(app.vault.getAbstractFileByPath(file.path));
}
app.commands.addCommand({
id: 'app:feelingLucky',
name: "I'm feeling lucky",
callback: lucky,
hotkeys: []
});
console.log("[I'm feeling lucky] added to commands");
%>