dsebastien / obsidian-dataview-serializer

Obsidian plugin that gives you the power of Dataview, but generates Markdown, making it compatible with Obsidian Publish, and making the links appear on the Graph.
https://developassion.gitbook.io/obsidian-dataview-serializer
MIT License
49 stars 5 forks source link

Ideas on removing the path from the link #17

Closed quantumgardener closed 2 weeks ago

quantumgardener commented 1 month ago

I use Quartz as my site generation tool. It takes Obsidian files and converts them to static html on a website. Your plugin is fantastic for closing the gap with Dataview pages.

Here's an example of it working. https://quantumgardener.info/maps/playstation-3-games

However, I have had to modify the Quartz code to get your pages to work properly. The reason is that you are including the full path from the root of the Obsidian vault in the link. I have to strip that out to get Quartz to think it's a normal Obsidian link.

[[Quartz/notes/Assetto Corsa Competizione.md|Assetto Corsa Competizione]] is the link that I get from the plugin. That doesn't work on the Quartz generated site. I have stripped the path, extension and alias to get [[Assetto Corsa Competizione]] which is exactly what Dataview does.

There may be a reason, but I don't understand why the path and extension is needed. If we can strip it out, your code will be useful in more places, including mobile (#11 )

Here is the code I'm running in Quartz (in ofm.ts)

 if (fp.startsWith("Quartz")) {
     // We have a Dataview Serializer Path. Strip it down to filename without path or extension
     if (fp.endsWith(".md")) {
          fp = path.basename(fp).substring(0, path.basename(fp).lastIndexOf('.'))
     }
     if (fp.endsWith(".webp")) {
          fp = path.basename(fp)
     }
}

I can probably help you with the code. I can certainly help with the testing. I don't know anything about packing up the code for the plug in.

dsebastien commented 1 month ago

Oh, I never noticed that, good catch!

I actually don't know why the full path is generated by the call to the tryQueryMarkdown method of the Dataview plugin. Maybe there's a parameter/setting we can pass to avoid that.

There are very few cases where the full path is necessary (let alone the extension). Normally, the full path is only needed for disambiguation if there are multiple notes with the same name in the vault.

In any case, we should be able to customize that manually if needed in that function: https://github.com/dsebastien/obsidian-dataview-serializer/blob/master/apps/plugin/src/app/utils/serialize-query.fn.ts#L14

dsebastien commented 1 month ago

I have asked the question on Dataview's GitHub discussion channel: https://github.com/blacksmithgu/obsidian-dataview/discussions/2412

quantumgardener commented 1 month ago

Yeah, unless you expand the link you'd never know. In Obsidian they just work.

Nicely put question. I'm not familiar with your code, so I'll take a look. Even if dataview can't resolve it, can it be intercepted and cleaned up?

This may help. https://github.com/blacksmithgu/obsidian-dataview/issues/2343#issue-2315182074 (Using dv.tryQueryMarkdown() got raw Markdown content, but use dv.paragraph() can't re-render correct in page)