Open LynetteCullens opened 6 months ago
const pageNum = dv.current().page;
const start = 10 * (pageNum - 1);
const end = 10 * pageNum;
const results = dv.pages('"Glossary"');
const regex = />\s\[\!theorem\]\s(.+?)((\n>\s.*?)*)\n/;
const rows = []
for (const page of results) {
const file = app.vault.getAbstractFileByPath(page.file.path)
// Read the file contents
const contents = app.vault.read(file)
// Extract the summary via regex
for (const callout of contents.match(new RegExp(regex, 'sg')) || []) {
const match = callout.match(new RegExp(regex, 's'))
rows.push([match[1], match[2], page.file.link])
}
};
const rows2 = rows.slice(start, end)
const totalPages = Math.ceil(rows.length / 10);
const options = rows.slice(0, totalPages).map((_, i) => `option(${i + 1})`).join(',');
const selector = `\`INPUT[inlineSelect(${options}):page]\``;
dv.span(`Page ${selector} out of *${totalPages}*`);
const cols = ['Title', 'Content', 'Page Link'];
dv.table(cols, rows2)
// You can update this to filter as you like - filtering for just your daily notes would be good
const pages = dv.pages('"Glossary"')
// This regex will find the contents of a specifically formatted callout
const regex = />\s\[\!theorem\]\s(.+?)((\n>\s.*?)*)\n/
const rows = []
for (const page of pages) {
const file = app.vault.getAbstractFileByPath(page.file.path)
// Read the file contents
const contents = app.vault.read(file)
// Extract the summary via regex
for (const callout of contents.match(new RegExp(regex, 'sg')) || []) {
const match = callout.match(new RegExp(regex, 's'))
rows.push([match[1], match[2], page.file.link])
}
}
dv.table(['Title', 'Content', 'Page Link'], rows)
So neither the dataview query nor dataviewjs worked right? (the dataview query looks like it should work)
For the dataviewjs, you don't do dv.table()
. You have to instead return an object with properties headers
and values
const data = dv.pages().map(f => [f.file.link, f.foo]);
return {
headers: ['file', 'foo'],
values: data
}
Something interesting-- The same way you make a metabind
plugin codeblock, you can create a dataedit
codeblock from within a dataview block like this:
dv.span("```dataedit\n" +
"TABLE test, date, bool\n" +
"```"
)
Which would allow you to render other things (like metabind
codeblocks or whatever you want) within the block while being able to utilize Dataedit's functionality.
The only meh thing about this approach is that after making an edit in the Dataedit table (within a dataview codeblock), editable table will still update quickly and without any flicker, but shortly after Dataview will flicker due to metadata changing (which is a known issue with Dataview and one of the reasons for Datacore being written with React).
From Dataview Type Query
obsidian.md-1714877932099.log
From Dataviewjs Type Query
obsidian.md-1714878245785.log