Skip to content

Commit

Permalink
fix: set alt value for contributor image with no complete name (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenshiAMD committed Sep 23, 2022
1 parent 9d82568 commit 109b261
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/generate/__tests__/fixtures/contributors.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
"contributions": ["translation"]
},
"nocompletename": {
"login": "nocompletename",
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
"contributions": ["translation"]
},
"nologin_badrole": {
"name": "Wildly Misconfigured",
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
Expand Down
10 changes: 10 additions & 0 deletions src/generate/__tests__/format-contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ test('format contributor with no GitHub account', () => {

expect(formatContributor(options, contributor)).toBe(expected)
})

test('format contributor with no complete name', () => {
const contributor = contributors.nocompletename
const {options} = fixtures()

const expected =
'<img src="https://avatars1.githubusercontent.com/u/1500684?s=150" width="150px;" alt="nocompletename"/><br /><sub><b>nocompletename</b></sub><br /><a href="#translation-nocompletename" title="Translation">🌍</a>'

expect(formatContributor(options, contributor)).toBe(expected)
})
4 changes: 3 additions & 1 deletion src/generate/format-contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const contributorTemplate = _.template(
const defaultImageSize = 100

function defaultTemplate(templateData) {
const name = escapeName(templateData.contributor.name)
const rawName =
templateData.contributor.name || templateData.contributor.login
const name = escapeName(rawName)
const avatar = avatarTemplate(
_.assign(templateData, {
name,
Expand Down

0 comments on commit 109b261

Please sign in to comment.