Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 01-15-2021, 03:45 AM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,364
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Template: avoid multiple images?

Quote:
Originally Posted by ownedbycats View Post
Question: I'm converting my fanfic column icon rules to a single advanced rule.

Code:
program: 
   f = field('#fanficcat');
   strcat
   (
    contains(f, "Dragon Age: Origins", 'dragonageorigins.png', ''), 
    contains(f, "Half-Life", 'halflife.png', ''), 
    contains(f, "Mass Effect", 'masseffect.png', ''), 
    contains(f, "The Elder Scrolls", 'theelderscrolls.png', ''), 
    contains(f, "Pokémon", 'pokemon.png', ''), 
    contains(f, "Portal", 'portal.png', ''), 
   )
It works except for when there's multiple values (#fanficcat is a tag-like). Clicking on one of the crossovers in the book list and opening the template editor shows "masseffect.pngpokemon.png".

What should I do?
Another question regarding this one:

Code:
 strcat
   (
    contains(f, "foo", 'foobar.png:', ''), 
    contains(f, "bar", 'foobar.png:', ''),  
   )
If a book has both "foo" and "bar", how do I get it to display foobar.png only once without using first_non_empty?

ownedbycats is offline   Reply With Quote
Old 01-15-2021, 05:30 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Moderator Notice
Moved to separate thread
In general, you should make a new thread for questions about existing templates. Or use the older thread, for that matter.

Last edited by chaley; 01-15-2021 at 05:44 AM.
chaley is offline   Reply With Quote
Advert
Old 01-15-2021, 05:43 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Another question regarding this one:

Code:
 strcat
   (
    contains(f, "foo", 'foobar.png:', ''), 
    contains(f, "bar", 'foobar.png:', ''),  
   )
If a book has both "foo" and "bar", how do I get it to display foobar.png only once without using first_non_empty?

First, why not use first_non_empty()? It does what you seem to want with the added benefit of priority. For example
Code:
program:
   f = field('#fanficcat');
   strcat
   (
    contains(f, "Dragon Age: Origins", 'dragonageorigins.png', ''), 
    contains(f, "Half-Life", 'halflife.png', ''), 
    contains(f, "Mass Effect", 'masseffect.png', ''), 
    contains(f, "The Elder Scrolls", 'theelderscrolls.png', ''), 
    contains(f, "Pokémon", 'pokemon.png', ''), 
    contains(f, "Portal", 'portal.png', ''), 
    first_non_empty(
        contains(f, "foo", 'foobar.png:', ''), 
        contains(f, "bar", 'foobar.png:', ''),  
       )
   )
This solves the problem you pose without using first_non_empty():
Code:
    contains(f, "^(foo|bar)$", 'foobar.png:', '')
Note the ^ and $ characters, called anchors in regex. Without anchors, contains will match the pattern anywhere in the string. For example, "bar" will match "wheelbarrow" and "Portal" will match "Starportal". My guess is that all of your comparisons should use anchors, e.g., '^Portal$'.
chaley is offline   Reply With Quote
Old 01-15-2021, 04:26 PM   #4
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,364
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That'll work.

In my case, I was adding generic media-type icons (e.g. a book or a game controller or a roll of film) to categories if I didn't have a more specific icon. It was appearing multiple times for crossovers though.

In hindsight, I also think I could've made a separate rule with first_non_empty.

Thank you

Last edited by ownedbycats; 01-15-2021 at 06:36 PM.
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to Do Multiple Replacements in a Save Template? rebeltaz Library Management 2 08-27-2020 01:03 AM
How to avoid adding borders to images and headings when importing to library epilandrus Conversion 4 03-06-2015 11:31 AM
help with saving template having multiple authors? miquele Library Management 2 04-16-2013 05:49 PM
How to avoid whits space when displaying images? huebi ePub 3 05-16-2012 02:53 PM
Avoid the "jagged" images in multiple e-readers nathanp ePub 8 03-10-2012 05:08 PM


All times are GMT -4. The time now is 09:07 AM.


MobileRead.com is a privately owned, operated and funded community.