Skip to content

Commit

Permalink
Fix APA author format when name is Editors of WikiHerbalist
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannimanetti11 committed Apr 9, 2024
1 parent 791245d commit f701846
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions inc/js/single-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,25 @@ document.addEventListener('DOMContentLoaded', () => {
}

// Formats author names according to APA 7th edition

window.formatAPAAuthors = function(authors) {
const authorsArray = authors.split(', ').map((author) => {
const parts = author.split(' ');
const lastName = parts.pop();
const initials = parts.map(name => `${name.charAt(0)}.`).join(' ');
return `${lastName}, ${initials}`;
});
if (authors === "Editors of WikiHerbalist" || authors === "WHAdmin") {
return authors;
}
else {
const authorsArray = authors.split(', ').map((author) => {
const parts = author.split(' ');
const lastName = parts.pop();
const initials = parts.map(name => `${name.charAt(0)}.`).join(' ');
return `${lastName}, ${initials}`;
});

if (authorsArray.length > 1) {
const lastAuthor = authorsArray.pop();
return `${authorsArray.join(', ')}, & ${lastAuthor}`;
} else {
return authorsArray[0]; // No need for '&' for a single author
if (authorsArray.length > 1) {
const lastAuthor = authorsArray.pop();
return `${authorsArray.join(', ')}, & ${lastAuthor}`;
} else {
return authorsArray[0]; // No need for '&' for a single author
}
}
}

Expand Down

0 comments on commit f701846

Please sign in to comment.