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

Embed Image links #142

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

ReconVirus
Copy link

Changed the way the image link are outputted so that they are embed ready instead of it just being a web link to the image

image
image

this allows dataview to work without any extra steps

image
image
image
image

Changed the way the image link are outputted so that they are embed ready instead of it just being a web link to the image
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reupload the files but the actual changes are on lines

MALAPI: 119, 153, 184

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reupload the files but the actual changes are on lines

OMDbAPI: 145, 177, 207

@mProjectsCode
Copy link
Owner

mProjectsCode commented May 2, 2024

Please run the formatter so that the diffs become useful.
The relevant command is bun run format in the root of the project, after installing the dependencies with bun i.

@ltctceplrm
Copy link
Contributor

If I might chime in, wouldn't it be easier to just have people who want it to be an embedded image for use in dataview to use a fixed dataview query to embed it?
Example:

Table ("!["+image+"|100]("+image+")") as "Poster"
From "Series"
WHERE type = "Series"
SORT file.name ASC

If all the image property becomes an embedded image then it might mess up people's workflows for instance if they use the URL to download images or something similar.

@ReconVirus
Copy link
Author

If I might chime in, wouldn't it be easier to just have people who want it to be an embedded image for use in dataview to use a fixed dataview query to embed it? Example:

Table ("!["+image+"|100]("+image+")") as "Poster"
From "Series"
WHERE type = "Series"
SORT file.name ASC

If all the image property becomes an embedded image then it might mess up people's workflows for instance if they use the URL to download images or something similar.

the dataview in the screenshot would be simpler and wouldnt just be limited to dataview, can you would be able to use it in something like =this.image which would pull the information from the image property and already embed the image without futher adding needed work to do so

image

would just be render as

image

and the other set of pictures for example

The image url is still there, it just makes it more useful within obsidian. For workflows that rely on the URL for downloading images, the URL can still be easily accessed and used as before. The change primarily aims to streamline the process of embedding images, making it more efficient in what the plugin does inside of obsidian.

all this does in the end is have the plugin already do the work that would be needed for the end user to do.

you ened up having to do

Table ("!["+image+"|100]("+image+")") as "Poster"
From "Series"
WHERE type = "Series"
SORT file.name ASC

when it could have be as simple as doing

Table image as "Poster"
From "Series"
WHERE type = "Series"
SORT file.name ASC

@ReconVirus
Copy link
Author

this would just be a step in the right direction for something like #137 and #134 where something like this would have been useful on properties thought would have benefited from using embeds

@ltctceplrm
Copy link
Contributor

ltctceplrm commented May 11, 2024

the dataview in the screenshot would be simpler and wouldnt just be limited to dataview, can you would be able to use it in something like =this.image which would pull the information from the image property and already embed the image without futher adding needed work to do so

I believe that =this.image is actually an inline dataview query and would not work without the dataview plugin

The image url is still there, it just makes it more useful within obsidian. For workflows that rely on the URL for downloading images, the URL can still be easily accessed and used as before. The change primarily aims to streamline the process of embedding images, making it more efficient in what the plugin does inside of obsidian.

I'm not convinced that the url is as easy to access as before, you'd have to strip the embed portion of the url each time

Additionally you'd completely lose the ability to choose a specific size for the images, with the current URL I can just do this to embed an image in a note and have it be a specific size:
![poster_movie_The Abyss|350](https://m.media-amazon.com/images/M/MV5BYmU4NmUxZjEtYjY0OC00ZDAwLTg0MGQtMDRkNDk5NWQ0OTQ5XkEyXkFqcGdeQXVyMjUzOTY1NTc@._V1_SX600.jpg)

It's all done automatically with a simple template and I don't see how it would be possible to choose specific sizes for images with this change.

I would like for #137 and #134 to be added as well but those would be a lot less disruptive than changing the image url to an embed.

Maybe if there was a toggle for it in the settings then people can choose?

Edit: Additionally wouldn't it be best to change the other APIs to embed the image as well so the plugin remains consistent?

@ReconVirus
Copy link
Author

I believe that =this.image is actually an inline dataview query and would not work without the dataview plugin

yes you are right, this would allow inline dataview query to work as well with embeds from the yaml

Additionally you'd completely lose the ability to choose a specific size for the images, with the current URL I can just do this to embed an image in a note and have it be a specific size: ![poster_movie_The Abyss|350](https://m.media-amazon.com/images/M/MV5BYmU4NmUxZjEtYjY0OC00ZDAwLTg0MGQtMDRkNDk5NWQ0OTQ5XkEyXkFqcGdeQXVyMjUzOTY1NTc@._V1_SX600.jpg)

It's all done automatically with a simple template and I don't see how it would be possible to choose specific sizes for images with this change.

the change is setup in away similar to a template as

`![](${result.images?.jpg?.image_url})`

which would allow the end user to give a title and allow whatever size they perfer to be input after importing the data with a blank [] so this wouldnt stop that from happening

Edit: Additionally wouldn't it be best to change the other APIs to embed the image as well so the plugin remains consistent?

right, i didnt do the other Apis as i thought the embeds would be more useful in something that would commonly have the most use for it. i fear the plugin in of it self isnt the most consistent after looking through the code.

@ltctceplrm
Copy link
Contributor

But again this would force people who use this plugin to also use dataview if they want to be able to do any of that, it's an added dependency and then you notes are less future proof.

Would it be alright if I just add a toggle in the settings and default it to off, so current users aren't impacted but they can change to it if they choose to? I'd also add the embedding to the other apis that have the image property.

@ReconVirus
Copy link
Author

Absolutely, adding a toggle in the settings seems like a balanced solution that respects the needs/wants of all users. This way, those who prefer the current functionality can maintain their workflow, while others can opt-in to the new feature if they find it beneficial.

extending the embedding functionality to other APIs that have the image property would enhance the overall utility of the plugin and something that i did overlooked.

So, yes, please proceed with adding the toggle and extending the embedding functionality. I believe these changes will be welcomed by the community.

@ltctceplrm
Copy link
Contributor

I sent you a pull request on your fork so you can merge it if you're okay with the code and then mProjectsCode can check it and see if he's okay with it too.

The text accompanying the toggle in the settings is just "Embed the poster urls as images in the yaml to integrate with dataview" but it can definitely be improved.
image

ReconVirus and others added 2 commits May 14, 2024 02:04
Added an option for the poster embeds and also added embeds to the other apis
@@ -108,7 +108,7 @@ export class MALAPI extends APIModel {
url: result.url,
id: result.mal_id,

plot: result.synopsis,
plot: result.synopsis ? result.synopsis.replace('[Written by MAL Rewrite]', '').trim() : '',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and line 177 isnt need on the MALAPI.ts, this is suppose to remove the end comment return from pulling plot synopsis. No all of them had it and this was something i personally add on my end, that ened up getting pushed to PR, this doesnt need to be added.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems useful to keep

@@ -279,6 +281,15 @@ export class MediaDbSettingTab extends PluginSettingTab {
void this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Embed posters in YAML')
.setDesc('Embed the poster urls as images in the yaml to integrate with dataview.')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pretty much sums it up nicely and no other way to put it, just adding a alternative

"Embed the URLs of the poster images within the image property using the image embedding syntax ![](URL). This will enable the images to directly integrate with Dataview, as opposed to simply being a hyperlink."

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save image links as markdown embeds in the frontmatter, for easier handling with e.g. Dataview.

@@ -75,7 +75,9 @@ export class BoardGameGeekAPI extends APIModel {
const boardgame = response.querySelector('boardgame')!;
const title = boardgame.querySelector('name[primary=true]')!.textContent!;
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
const image = boardgame.querySelector('image')?.textContent ?? undefined;
const image = this.plugin.settings.embedPosters
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing the ternary everywhere seems bad, as it's a lot of code duplication. This would be better as a general post-process step applied to all data models after the individual APIs created them.

@@ -108,7 +108,7 @@ export class MALAPI extends APIModel {
url: result.url,
id: result.mal_id,

plot: result.synopsis,
plot: result.synopsis ? result.synopsis.replace('[Written by MAL Rewrite]', '').trim() : '',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems useful to keep

src/settings/Settings.ts Outdated Show resolved Hide resolved
@@ -279,6 +281,15 @@ export class MediaDbSettingTab extends PluginSettingTab {
void this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Embed posters in YAML')
.setDesc('Embed the poster urls as images in the yaml to integrate with dataview.')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save image links as markdown embeds in the frontmatter, for easier handling with e.g. Dataview.

Copy link
Owner

@mProjectsCode mProjectsCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my previous review I wasn't refering to just the one terneray that I marked, but all the ternerys for images. They all do more or less the same, this surrounding the link with an embed can be done once for all media type models in a post process step.

@@ -18,6 +18,11 @@ export class BoardGameGeekAPI extends APIModel {
this.types = [MediaType.BoardGame];
}

processImageLink(boardgameElement: { querySelector: (arg0: string) => { (): any; new (): any; textContent: any } }) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a better type for this, no? I am guessing boardgame has a type that can be used here.

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

Successfully merging this pull request may close these issues.

3 participants