fix: set alt value for contributor image with no complete name (#335)

This commit is contained in:
Angel Aviel Domaoan 2022-09-24 01:17:50 +08:00 committed by GitHub
parent 9d82568f41
commit 109b2614d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -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",

View file

@ -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)
})

View file

@ -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,