<%*
const dv = app.plugins.plugins["dataview"].api;
const openPublishPanel = app.commands.commands["publish:view-changes"].callback;
const bookshelfQuery = `
TABLE WITHOUT ID
"" as Cover,
link(file.link, title) as Title,
last-read as "Last Read"
FROM "lit/books"
WHERE last-read
SORT last-read DESC
`
const articlesQuery = `
TABLE WITHOUT ID
link(file.link, title) as Title,
dateformat(file.ctime, "yyyy-MM-dd") as Created
FROM "" WHERE (
contains(file.path, "lit/readwise/articles/") or
contains(file.path, "lit/zotero/")
)
SORT file.ctime desc
`
const videoQuery = `
TABLE WITHOUT ID
link(file.link, title) as Title,
dateformat(file.ctime, "yyyy-MM-dd") as Created
FROM "lit/videos"
SORT file.ctime desc
`
const coursesQuery = `
TABLE WITHOUT ID
link(file.link, title) as Title,
dateformat(file.ctime, "yyyy-MM-dd") as Created
FROM "lit/courses"
SORT file.ctime desc
`
const textbooksQuery = `
TABLE WITHOUT ID
link(file.link, title) as Title,
dateformat(file.ctime, "yyyy-MM-dd") as Created
FROM "lit/textbooks"
SORT file.ctime desc
`
const files = [
{
"name": "hubs/book shelf.md",
"query": bookshelfQuery,
},
{
"name": "hubs/literature.md",
"lead": "Expand any callout below.",
"sections": [
{
"header": "articles",
"query": articlesQuery,
},
{
"header": "videos",
"query": videoQuery,
},
{
"header": "courses",
"query": coursesQuery,
},
{
"header": "textbooks",
"query": textbooksQuery,
},
]
}
];
await files.forEach(async (file) => {
if (!tp.file.find_tfile(file["name"])) {
await tp.file.create_new("", file["name"]);
new Notice(`Created ${file["name"]}.`);
}
const tFile = tp.file.find_tfile(file["name"]);
let fileContent = "%%Update with Alt + P%%\n";
if("lead" in file) {
fileContent += file["lead"] + "\n\n";
}
if ("sections" in file) {
for (const section of file["sections"]) {
fileContent += `> [!EXAMPLE]- ${section["header"].trim()}\n`;
const queryOutput = await dv.queryMarkdown(section["query"]);
fileContent += `> ${queryOutput.value || "No results found"}\n\n`;
}
} else {
const queryOutput = await dv.queryMarkdown(file["query"]);
fileContent += "\n" + (queryOutput.value || "");
}
try {
await app.vault.modify(tFile, fileContent);
new Notice(`Updated ${tFile.basename}.`);
} catch (error) {
new Notice("⚠️ ERROR updating! Check console. Skipped file: " + file["name"], 0);
}
});
openPublishPanel();
%>