quire
quire copied to clipboard
{% contributors %} inserts unnecessary comma with length==2
Before proceeding, make sure there isn’t an existing issue for this bug.
- [X] I have searched the existing issues and determined this is a new bug.
Expected Behavior
With two contributors in a publication configuration, I expect the {% contributors %}
shortcode to show the contributors names with "and" between them, eg: "Jane Smith and June Smith"
Actual Behavior
The shortcode emits contributor names with a command before "and", eg: "Jane Smith, and June Smith".
Steps to Reproduce
Populate the contributors list w/ two contributor records
Version Numbers
[buncheong-ware] quire-cli 1.0.0-rc.11 quire-11ty 1.0.0-rc.16 starter https://github.com/thegetty/[email protected] [System] quire-cli 1.0.0-rc.11 node v18.17.0 npm 6.14.18 os Darwin 22.6.0
Web Browser
No response
Relevant Terminal/Shell Output
No response
Supporting Information
No response
For anyone that may need it before a permanent fix is made, here's a workaround I've used before.
In _plugins/shortcodes/contributors.js
look for this block near the end of the file:
case 'string': {
const last = contributorNames.pop()
const namesString =
contributorNames.length >= 1
? contributorNames.join(', ') + ', and ' + last
: last
contributorsElement = `<span class='quire-contributor'>${namesString}</span>`
break
}
And replace it with this, which defines namesString
in a way that's sensitive to whether there are 1, 2, or 3 or more contributors:
case 'string': {
const last = contributorNames.pop()
let namesString = ''
if (contributorNames.length > 1) {
namesString = contributorNames.join(', ') + ', and ' + last
} else if (contributorNames.length == 1 ){
namesString = contributorNames + ' and ' + last
} else {
namesString = last
}
contributorsElement = `<span class='quire-contributor'>${namesString}</span>`
break
}
There is the same problem in the initials
output of the {% contributors %}
shortcode, but the same workaround can be applied, changing this in that same contributors.js
file:
case 'initials': {
const contributorInitials = contributorList.map(initials)
const last = contributorInitials.pop()
const nameString =
contributorInitials.length >= 1
? contributorInitials.join(', ') + ', and ' + last
: last
contributorsElement = `<span class="quire-contributor">${nameString}</span>`
break
}
To this:
case 'initials': {
const contributorInitials = contributorList.map(initials)
const last = contributorInitials.pop()
let namesString = ''
if (contributorInitials.length > 1) {
namesString = contributorInitials.join(', ') + ', and ' + last
} else if (contributorInitials.length == 1 ){
namesString = contributorInitials + ' and ' + last
} else {
namesString = last
}
contributorsElement = `<span class="quire-contributor">${nameString}</span>`
break
}