View Single Post
Old 10-29-2018, 10:33 PM   #9
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by Latios View Post
I think I am getting close how to fix it:

I have modified the code template like this:

Code:
{author_sort:'contains($,",",strcat(uppercase(list_item($,0,",")),", ",list_item($,1,","),", ",list_item($,2,","),", ",list_item($,3,",")),uppercase($))'}
And this is the new outcome:

When Author sort's metadata shows: Smith, Sam & Dallas, Ken
...applying the code you gave me, comes up like: SMITH, Sam & Dallas, Ken

For example, with more than two:
When Author sort's metadata shows: Ronald, Alex & Chan, Liu & Tiffany, Megan
...applying the code you gave me, comes up like: RONALD, Alex & Chan, Liu & Megan, Tiffany
What I did didn't handle multiple authors.
Quote:
The only thing missing now is to make the second and following last name's author into capital letters.

what am I missing?
For two names, it is:

Code:
{author_sort:'contains($,",",strcat(uppercase(list_item($,0,",")),", ",strcat(list_item(list_item($,1,","),0,"&")," & ",uppercase(list_item(list_item($,1,","),1,"&"))),", ",list_item($,2,","),", ",list_item($,3,",")),uppercase($))'}
But, doing it this way, means you need to know what is the maximum number of authors in the library. I think I have one with 17 authors, this would get absurd.

The way to do it is with a template function. To do this:
Open the calibre preferences and go to "Template functions"
  1. In "Function" put "author_sort_capitalized".
  2. In "Argument count" put "-1"
  3. In "Program code" paste the following:
    Code:
    def evaluate(self, formatter, kwargs, mi, locals):
        sort_data = mi.author_sort_map
        if not sort_data:
            return ''
        names = []
        for n in mi.authors:
            if n.strip():
                comma_index = sort_data.get(n).find(',')
                if comma_index > 0:
                    new_name = sort_data.get(n)[:comma_index].upper()
                    new_name += sort_data.get(n)[comma_index:]
                else:
                    new_name = sort_data.get(n).upper()
                names.append(new_name)
        return " & ".join(n for n in names)
    The formatting is important.
  4. Press the "Create" button.
  5. Press the "Apply" button and close the preferences.
  6. Where you want to use this put:
    Code:
    {:author_sort_capitalized()}

That seems to work here. There is probably a better way to do it, but, that's what comes to mind at the moment.
davidfor is offline   Reply With Quote