1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00

remove logoWidth param (#10878)

* remove `logoWidth` param
Fixes #10285

* remove `logoWidth` param
Fixes #10285

* fix: add `logoWidth` parameter to BaseService test
This commit is contained in:
jNullj 2025-03-02 13:16:02 +02:00 committed by GitHub
parent 779f8ae61c
commit 42e78083ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 6 additions and 43 deletions

View File

@ -47,10 +47,6 @@ const optionalStringWhenNamedLogoPresent = Joi.alternatives().conditional(
},
)
const optionalNumberWhenAnyLogoPresent = Joi.alternatives()
.conditional('namedLogo', { is: Joi.string().required(), then: Joi.number() })
.conditional('logoSvg', { is: Joi.string().required(), then: Joi.number() })
const serviceDataSchema = Joi.object({
isError: Joi.boolean(),
label: Joi.string().allow(''),
@ -66,7 +62,6 @@ const serviceDataSchema = Joi.object({
logoSvg: Joi.string(),
logoColor: optionalStringWhenNamedLogoPresent,
logoSize: optionalStringWhenNamedLogoPresent,
logoWidth: optionalNumberWhenAnyLogoPresent,
cacheSeconds: Joi.number().integer().min(0),
style: Joi.string(),
})

View File

@ -20,7 +20,7 @@ import toArray from './to-array.js'
// 1. When `?logo=` contains a simple-icons logo or contains a base64-encoded
// SVG, that logo is used. When a `&logoColor=` is specified, that color is
// used (except for the base64-encoded logos). Otherwise the default color
// is used. The appearance of the logo can be customized using `logoWidth`,
// is used.
// When `?logo=` is specified, any logo-related parameters specified
// dynamically by the service, or by default in the service, are ignored.
// 2. The second precedence is the dynamic logo returned by a service. This is
@ -52,11 +52,7 @@ export default function coalesceBadge(
colorB: legacyOverrideColor,
colorA: legacyOverrideLabelColor,
} = overrides
let {
logoWidth: overrideLogoWidth,
color: overrideColor,
labelColor: overrideLabelColor,
} = overrides
let { color: overrideColor, labelColor: overrideLabelColor } = overrides
// Only use the legacy properties if the new ones are not provided
if (typeof overrideColor === 'undefined') {
@ -73,7 +69,6 @@ export default function coalesceBadge(
if (typeof overrideLabelColor === 'number') {
overrideLabelColor = `${overrideLabelColor}`
}
overrideLogoWidth = +overrideLogoWidth || undefined
const {
isError,
@ -85,7 +80,6 @@ export default function coalesceBadge(
namedLogo: serviceNamedLogo,
logoColor: serviceLogoColor,
logoSize: serviceLogoSize,
logoWidth: serviceLogoWidth,
link: serviceLink,
cacheSeconds: serviceCacheSeconds,
style: serviceStyle,
@ -131,7 +125,6 @@ export default function coalesceBadge(
// If the logo has been overridden it does not make sense to inherit the
// original width or position.
logoSize = overrideLogoSize
logoWidth = overrideLogoWidth
} else {
if (serviceLogoSvg) {
logoSvgBase64 = svg2base64(serviceLogoSvg)
@ -143,12 +136,11 @@ export default function coalesceBadge(
namedLogoColor = coalesce(overrideLogoColor, serviceLogoColor)
}
logoSize = coalesce(overrideLogoSize, serviceLogoSize)
logoWidth = coalesce(overrideLogoWidth, serviceLogoWidth)
}
if (namedLogo) {
const iconSize = getIconSize(String(namedLogo).toLowerCase())
if (!logoWidth && iconSize && logoSize === 'auto') {
if (iconSize && logoSize === 'auto') {
logoWidth = (iconSize.width / iconSize.height) * DEFAULT_LOGO_HEIGHT
}

View File

@ -185,7 +185,6 @@ describe('coalesceBadge', function () {
{
namedLogo: 'appveyor',
logoColor: 'red',
logoWidth: 100,
},
{},
).logo,
@ -246,20 +245,6 @@ describe('coalesceBadge', function () {
})
})
describe('Logo width', function () {
it('overrides the logoWidth', function () {
expect(coalesceBadge({ logoWidth: 20 }, {}, {})).to.include({
logoWidth: 20,
})
})
it('applies the logo width', function () {
expect(
coalesceBadge({}, { namedLogo: 'npm', logoWidth: 275 }, {}),
).to.include({ logoWidth: 275 })
})
})
describe('Links', function () {
it('overrides the links', function () {
expect(

View File

@ -12,7 +12,6 @@ const globalQueryParams = new Set([
'logo',
'logoColor',
'logoSize',
'logoWidth',
'link',
'colorA',
'colorB',

View File

@ -36,7 +36,6 @@ const endpointSchema = Joi.object({
logoSvg: Joi.string(),
logoColor: optionalStringWhenNamedLogoPresent,
logoSize: optionalStringWhenNamedLogoPresent,
logoWidth: optionalNumberWhenAnyLogoPresent,
style: Joi.string(),
cacheSeconds: Joi.number().integer().min(0),
/*
@ -45,6 +44,7 @@ const endpointSchema = Joi.object({
passing it should not throw an error
*/
logoPosition: optionalNumberWhenAnyLogoPresent,
logoWidth: optionalNumberWhenAnyLogoPresent,
})
// `namedLogo` or `logoSvg`; not both.
.oxor('namedLogo', 'logoSvg')

View File

@ -101,13 +101,6 @@ The endpoint badge takes a single required query param: <code>url</code>, which
Supported for simple-icons logos only.
</td>
</tr>
<tr>
<td><code>logoWidth</code></td>
<td>
Default: none. Same meaning as the query string. Can be overridden by
the query string.
</td>
</tr>
<tr>
<td><code>style</code></td>
<td>
@ -156,7 +149,6 @@ export default class Endpoint extends BaseJsonService {
logoSvg,
logoColor,
logoSize,
logoWidth,
style,
cacheSeconds,
}) {
@ -170,7 +162,6 @@ export default class Endpoint extends BaseJsonService {
logoSvg,
logoColor,
logoSize,
logoWidth,
style,
// don't allow the user to set cacheSeconds any shorter than this._cacheLength
cacheSeconds: Math.max(

View File

@ -118,6 +118,8 @@ t.create('custom svg logo')
expect(body).to.include(getSimpleIcon({ name: 'npm' }))
})
// The logoWidth param was removed, but passing it should not
// throw a validation error. It should just do nothing.
t.create('logoWidth')
.get('.json?url=https://example.com/badge')
.intercept(nock =>
@ -132,7 +134,6 @@ t.create('logoWidth')
.expectBadge({
label: 'hey',
message: 'yo',
logoWidth: 30,
})
// The logoPosition param was removed, but passing it should not