Bookshelf by dataview with conditional clause for images from two sources. Is it possible?

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

For every book I have a note generated with booksearch plugin. I have a YAML in which there is a link to a cover image. Every so and often booksearch can’t find a image for a particular book and neither I can with google image.
I created a bookshelf using many tips from Bucaneer

Having local images I use in field of my YAML

cover: [[coverbook.jpg]]

while for cover image


Now, if I use this query dataview I can view my cover image taken from web in the bookshelf:

TABLE WITHOUT ID AS "Titolo", author as Author, ("![|100](" + cover + ")") as Cover, 
rating as Voto, Anno_di_lettura as "Anno letto", pages as "Pag."
From "002 Reading"
WHERE file != this.file

For cover image from web I have:

(“![|100](” + cover + “)”) as Cover,

with another query dataview I can see local images:

TABLE WITHOUT ID AS "Titolo", author as Author, embed(link(cover, "150")) as Cover, 
rating as Voto, Anno_di_lettura as "Anno letto", pages as "Pag." 
From "002 Reading" 
WHERE file != this.file

Where I use this code for visualizing local image:

embed(link(cover, “150”)) as Cover,

Last code came from this discussion Local image
(solution by mnvwvnm)

With first query I can’t see local image

And obviously I can’t see the first two images when I use the second query.

Is it possible to create a if-then clause for having both kind of images?

Things I have tried

I tried several solution without success. I can’t create a query in which web cover and local image can be seen in one bookshelf

embed(if(contains(cover, “http”) || contains(cover, “https”), link(cover, “150”), “file:///Users/gabriele/Documents/Obsidian%20Vault/Attachment”)) AS “Cover”,

choice(contains(cover, “http”) || contains(cover, “https”), embed(link(cover, “150”)),

embed(if(contains(Cover, “http”) || contains(Cover, “https”), link(Cover, “150”), (“./” + Cover))) AS “Cover”,

Try entering the following in a note, and see if it works in your setting:

Tags: f67785
- "[[coverbook.jpg]]"

TABLE WITHOUT ID typeof(cover),
  choice(typeof(cover) = "link", 
    embed(link(cover, "150")),
    ("![|100](" + cover + ")")) as Cover
FLATTEN coverlist as cover
WHERE file = this.file

If if works, then just the same choice() function in your other query, and it should work. The trick I’m using is to use typeof(cover) to detect whether it’s an ordinary link within the vault, or else it’s a string (presumably a web link) so then we use the other format.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.