Separate a list of authors

Hello

I have a problem understanding variables and how to separate a string, but first, a little bit of context. I read books on my Kindle. Then I centralize all the highlights (Kindle, command, podcasts, etc.) in Readwise. From Readwise, I import the highlights to Obisidian using the “Readwise Official” plugin.

I can’t solve the following problem

When importing from Kindle (sync), the “author” for the book reads: “Pauline Maclaran, Michael Saren, Barbara Stern, and Mark Tadajewski.” In that way, when I sync readwise and obsidian, I get the author as [[Pauline Maclaran, Michael Saren, Barbara Stern, and Mark Tadajewski]].

I am trying to split the comma-separated values and ditch the “and” connector, so the authors are exported to obsidian as [[Pauline Maclaran]] [[Michael Saren]] [[Barbara Stern]] [[Mark Tadajewski]]. I have played with a custom format, but I can’t separate the string. Does anyone know how to implement that in the readwise plugin?

Another problem

Similarly, I have been trying to construct a list of books in my vault using data view. I am currently using the following query:

dataview
TABLE author, source, dateformat(file.cday, "MMM yy") AS "imported"
FROM ""
WHERE category = "books"
SORT file.name, ASC

The query somehow lists the authors separated, but I if understand that bullet point correctly (see picture) is still one long sting. How can I separate the string in “dataview” and show, for example, only the first author? I have tried with “split” to separate the authors without success.

Thanks!

I just tested author: [[Pauline Maclaran]] [[Michael Saren]] in front matter, and dataview will not list the book. It allows only one [[author]]. It probably doesn’t make much sense to separate the authors for front matter. I think listing just the first author in front matter, and the full list in the “Page metadata” section of the readwise import will be a better implementation.

Accordingly, my new idea is to modify the following to include just the first author (the string before the first comma) when readwise exports to obsidian.
author: {% if author %}[[{{author}}]]{% endif %}

Hi.
Well, I see here many questions, but my answer is focused in only one: the right syntax for a list/array (multiple values) in yaml frontmatter.

(and I don’t know readwise plugin)

About yaml frontmatter:

  1. First rule for links: in yaml obsidian links need to use quotation marks
field: "[[note A]]"
  1. For multiple values you can use two formats:
  • for links
field: ["[[note A]]", "[[note B]]"]

or 

field:
  - "[[note A]]"
  - "[[note B]]"
  • for strings
key: [value 1, value 2, value 3]

or

key: ["This is a more complex string! With punctuation, etc.", "another string, with more words", value 3]

or

key:
  - value 1
  - value 2
  - value 3

attention: in ‘vertical’ format use two spaces before “-”, not indentation.

2 Likes

Many thanks! I was using yaml frontmatter incorrectly :man_facepalming:

it is normal, I had the exact same problem couple of days ago until mnvwvnm helped me. it is counter-intuitive. also don’t forget that there is a difference for accepting lists between yaml and dataview (in note fields), you should use brackets for or bullet points for lists on yaml. for dataview you should only use quotation marks and comma like:
authors:: “[[First author]]”, “[[Second author]]”, etc

and links don’t get updated and recognized as proper links in yaml so I always use put them as a dataview key value pair if they are going to contain wikilinks.

Got it. I have everything working in Obsidian. I just need to get Readwise to export the authors separated, which means separating the sting by commas when there are multiple authors.

I got in contact with Readwise support, and they provided me the following:

You can split authors using the following:

{% if author %}{% set authors = author.replace(", and ", ", ").replace(" and ", ", ").split(", ") %}{%if authors|length == 1%}- Author: [[{{author}}]] {% else %}- Authors: {%- for anAuthor in authors %} [[{{anAuthor}}]]{% endfor %}{% endif %}{% endif %}

This will split
author: Author One, Author Two, and Author Three and Author Four
into
-Authors:[[AuthorOne]][[AuthorTwo]][[AuthorThree]][[AuthorFour]]

I am happy to report that that solves my problem with the comma-separated authors when linking Readwise and Obsidian.

2 Likes

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