Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{% contributors %} inserts unnecessary comma with length==2 #873

Open
1 task done
cbutcosk opened this issue Oct 27, 2023 · 1 comment
Open
1 task done

{% contributors %} inserts unnecessary comma with length==2 #873

cbutcosk opened this issue Oct 27, 2023 · 1 comment
Assignees
Labels
bug Actual behavior does not match expected behavior quire-11ty This is an issue with the quire-11ty package status:backlog Issue is a lower priority but needs to eventually be addressed workaround Issue has a workaround

Comments

@cbutcosk
Copy link
Collaborator

Before proceeding, make sure there isn’t an existing issue for this bug.

  • 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

@cbutcosk cbutcosk added the status:triage needed Issue needs to be triaged by the Quire team. This label is automatically applied to new issues. label Oct 27, 2023
@geealbers
Copy link
Member

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
}

@geealbers geealbers added the workaround Issue has a workaround label Dec 5, 2023
@Erin-Cecele Erin-Cecele added bug Actual behavior does not match expected behavior quire-11ty This is an issue with the quire-11ty package status:backlog Issue is a lower priority but needs to eventually be addressed and removed status:triage needed Issue needs to be triaged by the Quire team. This label is automatically applied to new issues. labels Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Actual behavior does not match expected behavior quire-11ty This is an issue with the quire-11ty package status:backlog Issue is a lower priority but needs to eventually be addressed workaround Issue has a workaround
Projects
None yet
Development

No branches or pull requests

3 participants