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

Not only elink() but also dynamic image links? #137

Open
Moonbase59 opened this issue Apr 23, 2021 · 6 comments
Open

Not only elink() but also dynamic image links? #137

Moonbase59 opened this issue Apr 23, 2021 · 6 comments

Comments

@Moonbase59
Copy link

@Moonbase59 Moonbase59 commented Apr 23, 2021

Having elink() is really useful.

Do you think it would be possible to also get something like ilink() and eilink() in order to dynamically create internal and external image links?

Thinking of internal/external images to be shown, based on YAML frontmatter data, like location-based weather images, user avatars or images, etc.

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Apr 24, 2021

Hmm, actually I can probably do that right now. I was looking at general image embedding which is a little more annoying (mainly figuring out how to specify when to embed/when not to embed), but have an explicit function which renders an inline image seems pretty straightforward.

@ngirard
Copy link

@ngirard ngirard commented Jun 4, 2021

Count me interested ;-)

@jt196
Copy link

@jt196 jt196 commented Nov 23, 2021

Been doing a bit of research this morning and found this. I think it's a feature I'd like. Spent the last hour trying to embed an image from yaml frontmatter but it's not working. Best I can do is have the url/source with this:

![image]\(`=this.image_local`\)

But that gives me this:

![image](./_resources/01B90486-2AB0-45FD-B5B1-BF148BBC0869-485-0008613D6C46C6D2.jpg)

As I think @Moonbase59 mentioned in one of the forum posts, must be to do with the parsing order or some such.

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Nov 25, 2021

That specific way to do embeds is unlikely to ever work - Dataview runs after the markdown renderer, so the markdown renderer will never pick up that as an image link.

I think this will likely need explicit function support (elink() or ilink() or something similar).

@jt196
Copy link

@jt196 jt196 commented Nov 25, 2021

So, tested and this kind of works using dataviewjs, very much based on some of the code that Moonbase put up on the Obsidian forums.

I had some issues where the photos would sometimes render, sometimes not. I'm assuming this is again, a render engine issue. Any ideas how to fix this? No console errors or anything. Maybe it's just a matter of opening and closing the note, or refreshing the page.

---
photo_thumbnail: _resources/985D5316-AD96-4673-970B-A7C3366C218C-485-0002EE52E3B1C099.jpg
---

Single photo:

var path = dv.current().photo_thumbnail
var link = '![image](' + path + ')'
dv.paragraph(link)

Loop through a list of photos in the YAML:

---
photos: 
  - _resources/985D5316-AD96-4673-970B-A7C3366C218C-485-0002EE52E3B1C099.jpg
  - _resources/985D5316-AD96-4673-970B-A7C3366C218C-485-0002EE52E3B1C088.jpg
---
var i;
for (i=0; i < dv.current().photos.length; i++) {
	var path = dv.current().photos[i];
	var link = '![image](' + path + ')'
	dv.paragraph(link);
}

@blacksmithgu
Copy link
Owner

@blacksmithgu blacksmithgu commented Nov 26, 2021

The fact that embeds work at all in Dataview is an Obsidian bug - the markdown renderer that plugins use does not support them at all currently.

If you want to hack at it, the best option would be to look at the generated HTML for an image in Obsidian and then replicate that in your script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants