Dataview – parsing author information

I’m using Dataview to display a list of articles (linked title + authors). I’m using regexeplace, to shorten the title (dropping subtitles after the colon), and I’d also like to reduce the author info to surnames only. I’ve experimented and researched regex and substring approaches, but have not found a solution that gets close to working.

My current working code:

TABLE WITHOUT ID
link(file.link, regexreplace(title, ":.*$", "")) AS "Title", authors AS "Authors"
FROM "Literature" AND -#todo/unread
SORT authors asc
WHERE contains(file.name, "@")

To forgo any confusion: the “Where contains” limits to my article notes as these start with “@”.

The current result is:

Title Authors
Title of article John Smith, Jane Other

What I’d like to do is have:

Title Authors
Title of article Smith, Jane

Currently, the authors are a text-field in my properties. I’ve tried reworking them to a list (which would need to be flattened after parsing, right?) Yet, I’m not sure if this is needed or just overcomplicated things.

What is the best approach to streamline the list? I welcome any suggestions to help me further my understanding and note-keeping tactics. Thanks in advance!

Extracting the surnames can be done in a multitude of ways, and I reckon the step you were missing is to use map on the list to address each name separately. Try the following in a note of its own:

---
authors:
  - John Smith
  - Jane Other
---

```dataview
TABLE WITHOUT ID authors, Surnames
WHERE file = this.file
FLATTEN list(map(authors, (a) => reverse(split(a, " "))[0])) as Surnames
```

If you in some case have stored the authors in a text field (aka a single author not in list format), you might need to replace the map(authors, ... ) with map( flat(list(authors)), ... )

My solution for getting to the surnames is to split the author name by space, reverse the list, and then selecting the “first” (which actually is the last due to the reversal) to become the surname of that author. This will of course fail with authors with multiple surnames… :slight_smile:

Many thanks! Sorry, for not responding sooner. The alert didn’t come through.

Switching to lists made this work perfectly (I have multiple authors are times, so using a text field only gives one name).

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