1

It would be good to sort lists using an author's last name.

I have this code in one of the tiddlers, it lists all the tiddlers tagged 'author' and sorts alphabetically:

<$list filter='[tag[author]sort[title]]'>

</$list>

e.g.

Adam Robinson
Andrew Adonis
Benjamin Franklin
Dale Carnegie
Daniel Priestley
George Leonard

I would like the list to be sorted by last name, so it looks like this:

Adonis, Andrew 
Carnegie, Dale
Franklin, Benjamin
Leonard, George
Priestley, Daniel
Robinson, Adam 

Any ideas how to do this?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Hal
  • 27
  • 4

2 Answers2

0

Easy option: Add a ByLastName field populated the way you want and sort on that.

Medium option: Introduce the notion of generated fields into tiddlywiki.

Hard option: Modify the sort filter to call a macro with whatever data you specify and then sort the original list based on the result.

Arlen Beiler
  • 15,336
  • 34
  • 92
  • 135
0

In recent versions of TiddlyWiki, you can do this with the sortsub operator, which sorts based on the results of applying a filter expression to the inputs. Note that when you use this operator (or any other operator that takes a subfilter), you have to define the subfilter using a macro, or there's no way for TiddlyWiki to tell which square brackets are part of the main filter and which are part of the subfilter.

Here's a minimal working version:

\define myfilt() [split[ ]last[]]

<$list filter="[tag[author]sortsub<myfilt>]">
  ...
</$list>

To get the display to show up as "Lastname, Firstname", as in your example, rather than just showing the title of the tiddler as is:

\define myfilt() [split[ ]last[]]

<$list filter="[tag[author]sortsub<myfilt>]">
  <$set name=formattedName value={{{ [all[current]split[ ]last[]addsuffix[, ]] [all[current]split[ ]butlast[]] +[join[]] }}}>
    <$link to=<<currentTiddler>>><<formattedName>></$link><br>
  </$set>
</$list>

We calculate the new format using a filter in {{{ triple curly braces }}} and assign it to a variable (note the use of butlast[] rather than first[] so that if someone has more than two names, the middle ones go on the end rather than disappearing). Then we create a link whose text is that new formatted version, and whose target is the original tiddler name.

Soren Bjornstad
  • 1,292
  • 1
  • 14
  • 25