Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It Seems Like It Choked: Uncaught (in promise) Syntax Errors #4

Open
LynetteCullens opened this issue May 5, 2024 · 3 comments
Open
Labels
bug Something isn't working investigating

Comments

@LynetteCullens
Copy link

From Dataview Type Query

TABLE mathLink-blocks.AltNotation, mathLink-blocks.Dimensions, mathLink-blocks.LinkedDimensions, mathLink-blocks.StaticDimensions, mathLink-blocks.LinkedStaticDimensions, mathLink-blocks.MKS, mathLink-blocks.CGS,mathLink-blocks.FPS, mathLink-blocks.LinkedFormula
FROM "Glossary"
LIMIT 50

obsidian.md-1714877932099.log

From Dataviewjs Type Query

const {fieldModifier: f} = this.app.plugins.plugins["metadata-menu"].api; 
dv.table (["File", "mathLink", "AltNotation", "Dimensions", "LinkedDimensions", "StaticDimensions", "LinkedStaticDimensions", "MKS", "CGS", "FPS", "LinkedFormula"], 
	await Promise.all(dv.pages('"Glossary"').map(async p => [ 
		p.file.link,
		await f(dv, p, "mathLink"),
		await f(dv, p, "mathLink-blocks.AltNotation"), 
		await f(dv, p, "mathLink-blocks.Dimensions"),
		await f(dv, p, "mathLink-blocks.LinkedDimensions"), 
		await f(dv, p, "mathLink-blocks.StaticDimensions"),
		await f(dv, p, "mathLink-blocks.LinkedStaticDimensions"),
		await f(dv, p, "mathLink-blocks.MKS"),
		await f(dv, p, "mathLink-blocks.CGS"),
		await f(dv, p, "mathLink-blocks.FPS"),
		await f(dv, p, "mathLink-blocks.LinkedFormula"), 
		]) 
)) 

obsidian.md-1714878245785.log

@LynetteCullens
Copy link
Author

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)

obsidian.md-1715178564263.log

// 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)

obsidian.md-1715178722797.log

@unxok unxok added bug Something isn't working investigating labels May 12, 2024
@unxok
Copy link
Owner

unxok commented May 12, 2024

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
}

@unxok
Copy link
Owner

unxok commented May 30, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigating
Projects
None yet
Development

No branches or pull requests

2 participants