obsidian-simple-embeds icon indicating copy to clipboard operation
obsidian-simple-embeds copied to clipboard

Add a generic link preview source

Open udbhav-s opened this issue 3 years ago • 2 comments
trafficstars

I added an additional source which generates a generic link preview for links that failed to match with any other source. It can be toggled on or off like any of the other sources and adds a single dependency (link-preview-js).

image

udbhav-s avatar Aug 15 '22 12:08 udbhav-s

I added a cache that saves fetched metadata into storage so it doesn't make new requests every time you toggle reading view on a page. There's also an option to clear it in the settings if the user wants to refetch out of date metadata or it can be disabled entirely.

udbhav-s avatar Aug 16 '22 12:08 udbhav-s

Thanks for working on this—was something I considered doing, maybe as a separate plugin. I'm going to start taking a look today.

samwarnick avatar Aug 30 '22 23:08 samwarnick

Sorry it's been a while, I started college last month and got busy. I swapped out the cache in settings for a JSON file in the vault that is loaded asynchronously. Generic preview defaults to false now and I've also removed the unused rollup json plugin dependency.

udbhav-s avatar Oct 08 '22 03:10 udbhav-s

I'm really looking forward to this getting merged, I've been wanting solid dynamic embeds for any link in Obsidian since I started using it and this looks like it will be pretty nearly perfect!

ChristinWhite avatar Oct 20 '22 20:10 ChristinWhite

@udbhav-s thanks a bunch for those changes. They're looking pretty good. One issue I'm seeing is that I'm getting an error because genericPreviewCache.json does not exist. So it seems like the promise that creates/reads that file does not get called. Also might want to use this.app.vault.configDir + "/plugins/simple-embeds/" to save the file in the plugin rather than the vault. I've seen other plugins do that, so I think that might be the preferred way.

I know you're probably busy with school, so I'll make some time this next week to take a deeper look and see if I can make a fix. But if you're able to take a look, even better.

samwarnick avatar Oct 22 '22 18:10 samwarnick

Looks like I wasn't awaiting the Promise that checked if the file didn't exist before creating it, should be fixed now! Also changed the location of the cache file to be in the plugin directory.

udbhav-s avatar Oct 22 '22 18:10 udbhav-s

@udbhav-s thanks so much! Seems to be working pretty well on desktop, so I'm going to go ahead and merge this. I did notice that it's not working on iOS. I suspect that cheerio, a dependency of link-preview-js uses some apis not available on iOS. So after I merge this I will make a couple changes to make it so this will only run on desktop for now. And I'll make another issue to look into getting it to work on iOS. Should hopefully get it ready to be released later today.

Thanks again for this!

samwarnick avatar Oct 24 '22 14:10 samwarnick

This is great, but it doesn't seem like this works in Live Preview mode? I do have "Show Embeds in Live Preview (beta)" enabled, but I only see the link previews when I switch to standard preview mode.

richardbowman avatar Nov 03 '22 12:11 richardbowman