Replace one character in front matter with another character in Dataview

I use “Book Search” Plugin to fetch book details & add them as front matter.

When I add the front matter, author column is fetched like this.

author: Bruce Bueno de Mesquita, Alastair Smith

I fetch this data using the dataview script on a new page called “Book Summary Library”

:page_facing_up:book_summary_library.md :point_down:t3:

TABLE WITHOUT ID
	link(file.link, title) as Title,
	"![|60](" + cover + ")" as Cover,
	"#"+author as Author,
	category as Category,
	total as Pages
FROM #Book-Summary📔 
WHERE !contains(file.path, "Templates")
SORT title ASC

It fetches all notes with #Book-Summary📔 tag & make it into a table.

  • I want the Author column to show clickable author tag.
  • I use “-” for whitespace & “:man_beard:” as prefix for author tags.
    • eg : #Ray Dalio as #:man_beard:Ray-Dalio
  • Sometimes there are two authors for one book. they are seperated by ", ".
  • I want it to display like this
    • eg: #Bruce Bueno de Mesquita, Alastair Smith as #:man_beard:Bruce-Bueno-de-Mesquita , #:man_beard:Alastair-Smith

Basicaly,

  • I want to change “whitespace” into “-”.
  • Also, if possible “comma + whitespace” into “:man_beard:#”

Please help :pray:

2 Likes

Best practice for multiple values in a field is the use of syntax for an array/list.
This:

author:
  - Bruce Bueno de Mesquita
  - Alastair Smith

or

author: [Bruce Bueno de Mesquita, Alastair Smith]

because author: Bruce Bueno de Mesquita, Alastair Smith is a simple value (a string), not multiple values.

But once you’re using the simple value, let’s try do something with that.

Try replace "#"+author as Author by

map(split(author, ", "), (a) => "#🧔" + replace(a, " ", "-")) AS Author

(attention: some emojis don’t work because they add some extra characters, breaking the continuity of “#emojiauthor-name”. the emoji you use - man_beard - is one of the cases)

EDIT: if you want to return to format “v1, v2” (joining values with comma as separator, use join(map(split(author, ", "), (a) => "#🧔" + replace(a, " ", "-"))) AS Author)

2 Likes

Nice, Working Perfectly. :blush:

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