Skip to content

Commit 109b261

Browse files
authoredSep 23, 2022
fix: set alt value for contributor image with no complete name (#335)
1 parent 9d82568 commit 109b261

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
 

‎src/generate/__tests__/fixtures/contributors.json

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
2626
"contributions": ["translation"]
2727
},
28+
"nocompletename": {
29+
"login": "nocompletename",
30+
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",
31+
"contributions": ["translation"]
32+
},
2833
"nologin_badrole": {
2934
"name": "Wildly Misconfigured",
3035
"avatar_url": "https://avatars1.githubusercontent.com/u/1500684",

‎src/generate/__tests__/format-contributor.js

+10
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,13 @@ test('format contributor with no GitHub account', () => {
7777

7878
expect(formatContributor(options, contributor)).toBe(expected)
7979
})
80+
81+
test('format contributor with no complete name', () => {
82+
const contributor = contributors.nocompletename
83+
const {options} = fixtures()
84+
85+
const expected =
86+
'<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>'
87+
88+
expect(formatContributor(options, contributor)).toBe(expected)
89+
})

‎src/generate/format-contributor.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const contributorTemplate = _.template(
1717
const defaultImageSize = 100
1818

1919
function defaultTemplate(templateData) {
20-
const name = escapeName(templateData.contributor.name)
20+
const rawName =
21+
templateData.contributor.name || templateData.contributor.login
22+
const name = escapeName(rawName)
2123
const avatar = avatarTemplate(
2224
_.assign(templateData, {
2325
name,

0 commit comments

Comments
 (0)
Please sign in to comment.