<%*
const dv = app.plugins.plugins["dataview"].api;
const openPublishPanel = app.commands.commands["publish:view-changes"].callback;
const fileAndQuery = new Map([
// Meta
[
"Index of all indices",
'LIST rows.file.link FROM "indices" FLATTEN file.folder as Folder FLATTEN split(Folder, "/")[1] AS Subfolder GROUP BY join(list(join(list("**", upper(Subfolder)[0], substring(Subfolder, 1, length(Subfolder))), ""), "indices**"), " ")'
],
[
"Index of all notes",
'TABLE WITHOUT ID file.link AS Note, description AS Description FROM "notes" SORT file.link ASC'
],
[
"Index of all notes by tag",
'LIST rows.file.link FROM "notes" FLATTEN file.etags AS tags GROUP BY join(list("**", substring(tags, 1, length(tags)), "**"), "")'
],
[
"Index of all tags (alpha sort)",
'TABLE length(rows.file.name) AS Notes FROM "notes" FLATTEN file.etags AS Tags GROUP BY Tags'
],
[
"Index of all tags (count sort)",
'TABLE length(rows.file.name) AS Notes FROM "notes" FLATTEN file.etags AS Tags GROUP BY Tags SORT length(rows.file.name) DESC'
],
[
"Index of original notes",
'LIST WITHOUT ID file.link FROM "notes" WHERE original = true SORT file.link ASC'
],
[
"Index of random notes",
'LIST WITHOUT ID file.link FROM "notes" FLATTEN date(now) as Now FLATTEN (file.mtime.year + file.mtime.hour + file.mtime.day + file.mtime.hour + file.mtime.minute + file.mtime.second + file.size + Now.hour + Now.minute + Now.second) * 15485863 as Hash FLATTEN ((Hash * Hash * Hash) % 2038074743) / 2038074743 as Rand WHERE max(Rand) SORT Rand LIMIT 5'
],
[
"Index of recent notes",
'LIST WITHOUT ID join(list(file.link, dateformat(file.mtime,"yyyy-MM-dd")), " (") + ")" FROM "notes" SORT file.mtime DESC LIMIT 5'
],
//Thematic
[
"Index of cognitive biases",
'TABLE WITHOUT ID file.link AS Note, description AS Description FROM "notes" AND #Psychology/Cognitive/Bias SORT file.link ASC'
],
[
"Index of mathematics",
'TABLE WITHOUT ID file.link AS Note, description AS Description FROM "notes" AND #Mathematics SORT file.link ASC'
],
[
"Index of parables",
'TABLE WITHOUT ID file.link AS Note, description AS Description FROM "notes" AND #Model/Parable SORT file.link ASC'
]
]);
await fileAndQuery.forEach(async (query, filename) => {
if (!tp.file.find_tfile(filename)) {
await tp.file.create_new("", filename);
new Notice(`Created ${filename}.`);
}
const tFile = tp.file.find_tfile(filename);
const queryOutput = await dv.queryMarkdown(query);
const fileContent = `${queryOutput.value}`;
try {
await app.vault.modify(tFile, fileContent);
new Notice(`Updated ${tFile.basename}.`);
} catch (error) {
new Notice("⚠️ ERROR updating! Check console. Skipped file: " + filename , 0);
}
});
openPublishPanel();
%>