oleeskild / obsidian-digital-garden

MIT License
1.39k stars 125 forks source link

function convertDataViews incompatible with dataviewJS file.link #446

Closed jonathanhung closed 1 year ago

jonathanhung commented 1 year ago

Using this code in obsidian:

    const posts = dv.pages('"200 Posts"');
    dv.list(posts.file.link);

The div.innerHTML returned by convertDataView is an empty list (seen in obsidian console)

Expected (seen in Obsidian)

image

Conclusion: using file.link works in obsidian but not with digital garden?

oleeskild commented 1 year ago

Could be related to #254

oleeskild commented 1 year ago

This should have been fixed in the latest release. Please let me know if updating to the latest version fixes it for you

jonathanhung commented 1 year ago

updated to 2.51.0 but still not getting desired behavior.

Here are the three queries image

Here's the render in the digital garden: image

They are rendering (both in Obsidian and Digital Garden), but I don't think eleventy or markdownit is converting the links that come from dataviewJS.

image

You can see in this final image that a class name block-language-dataview is added to the <ul> when using DV, but when using DVJS it gets just dataview

I'm guessing there's a missing slugify arg somewhere in markdownit or eleventy. Or the logic doesn't have the right conditional to locate ul.dataview

jonathanhung commented 1 year ago

ahh, it looks like Eleventy wants to find children of .cm-s-obsidian - I got rid of that class in the template to gain control of the CSS cascade. let me see what happens

Edit: added back that classname and it still isn't converting those links to slugified links

image

Looking at the markdown file itself it looks like eleventy or markdownit / slugify just ignores the HTML and converts the markdown link.

jonathanhung commented 1 year ago

Co-Pilot wants me to include a filter in the nunjucks template to slugify the URLs. I went into eleventyJS and after some back and forth with Co-Pilot, I added a clause to the eleventyJS link filter that finds .md links and slugifies them, and this solves it.

.replace(/href="([^"]+)"/g, function (match, p1) {
        if (p1.endsWith(".md")) {
          const urlPath = p1.replace(/\.md$/, "");
          const slugifiedUrlPath = urlPath
            .split("/")
            .map((part) => slugify(part))
            .join("/");
          return `href="/${slugifiedUrlPath}/"`;
        } else {
          return match;
      }})
jonathanhung commented 1 year ago

Also worth sharing that when you use dataviewJS function dv.markdownList it still outputs markup not markdown.

image image

Presently trying to amend the link filter in eleventyconfig to find those urls and slugify them. or to create a new filter

oleeskild commented 1 year ago

Yep, you are right @jonathanhung, the links from dataviewJs is not working. It's due to the plugin not handling rewriting html links, it only handles markdown links. I'm currently tracking this issue on #346

oleeskild commented 1 year ago

This has now been fixed in the latest version of the template. Updating the template should result in all dataviewjs links behave similar to other links.