Book Search plugin, splitting multiple authors

Hi fellow travelers!
I love using the Book Search plugin by anpigon, the only problem is the {{author}} field is a single string, which is okay for single author books but a bit messy for multi author books as I like to turn my author’s names into links so I can have author pages that list all the books by that author (I also manually include bio info from Goodreads or Wikipedia).
Any way… I needed a way to split and reformat the {{author}} field so I came up with this.
Be warned this is a complete hack job and probably needs cleaning up by someone that knows what they are doing :slight_smile:

So here is my new book template. I hope it’s useful to someone.
EDIT: Sorry the code highlighter doesn’t like my inline comments.

title: {{title}}
let authors = "{{author}}";
const names = authors.split(", ")
var arrayLength = names.length;
let authorFL = "[[" + names[0] + "]]";
for (var i = 1; i < arrayLength; i++) {
    authorFL = "[[" + names[i] + "]]" + ", " + authorFL;
const result = []
for (const name of names) {
	const nameParts = name.trim().split(" ") //remove redundant space and break the string down into array items (names)
	const lastName = nameParts.pop() //take the last item
	nameParts.unshift(lastName + ",") //add the last item to the first position
	result.push(`"${nameParts.join(" ")}"`) //add "" to a name

const authorLF = result.join(", ") //make the entire array to become a string with a separator `,`
authors: <% authorFL %>
authorLF: <% authorLF %>
publisher: {{publisher}}
publish: {{publishDate}}
pages: {{totalPage}}
isbn10: {{isbn10}}
isbn13: {{isbn13}}
cover: {{coverUrl}}
# [[{{title}}]]
By <% authorFL %>
1 Like

Thank you for sharing this code. I too have been bothered by the problem of multiple authorship when using the Book Search plugin. This is very helpful. I deleted the last line of code, since in my version of the plugin it merely duplicated the cover image. Otherwise the code works perfectly.

For the excessively fastidious (I’m talking librarian cataloguers), the plugin occasionally errs (a) by treating as an “author” an editor or a translator who is prominently mentioned in the bibliographic record, and (b) by occasionally dropping a subtitle. If you’re curious, use the plugin with this code to search for Dialectic of Enlightenment, by Max Horkheimer and Theodor Adorno (Stanford Univ Press, 2002). The plugin misses the subtitle and includes the editor as an author. Oh well, nobody’s perfect.