feat(endpoint-badge): add logoSize support (#10132)

This commit is contained in:
LitoMore
2024-12-31 23:45:39 +08:00
committed by GitHub
parent c567f6cde4
commit 85b44b9152
4 changed files with 28 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ const endpointSchema = Joi.object({
namedLogo: Joi.string(),
logoSvg: Joi.string(),
logoColor: optionalStringWhenNamedLogoPresent,
logoSize: optionalStringWhenNamedLogoPresent,
logoWidth: optionalNumberWhenAnyLogoPresent,
style: Joi.string(),
cacheSeconds: Joi.number().integer().min(0),

View File

@@ -93,6 +93,14 @@ The endpoint badge takes a single required query param: <code>url</code>, which
the query string. Only works for simple-icons logos.
</td>
</tr>
<tr>
<td><code>logoSize</code></td>
<td>
Default: none. Make icons adaptively resize by setting <code>auto</code>.
Useful for some wider logos like <code>amd</code> and <code>amg</code>.
Supported for simple-icons logos only.
</td>
</tr>
<tr>
<td><code>logoWidth</code></td>
<td>
@@ -147,6 +155,7 @@ export default class Endpoint extends BaseJsonService {
namedLogo,
logoSvg,
logoColor,
logoSize,
logoWidth,
style,
cacheSeconds,
@@ -160,6 +169,7 @@ export default class Endpoint extends BaseJsonService {
namedLogo,
logoSvg,
logoColor,
logoSize,
logoWidth,
style,
// don't allow the user to set cacheSeconds any shorter than this._cacheLength

View File

@@ -82,6 +82,22 @@ t.create('named logo with color')
expect(body).to.include(getSimpleIcon({ name: 'github', color: 'blue' }))
})
t.create('named logo with size')
.get('.svg?url=https://example.com/badge')
.intercept(nock =>
nock('https://example.com/').get('/badge').reply(200, {
schemaVersion: 1,
label: 'hey',
message: 'yo',
namedLogo: 'github',
logoSize: 'auto',
}),
)
.after((err, res, body) => {
expect(err).not.to.be.ok
expect(body).to.include(getSimpleIcon({ name: 'github', size: 'auto' }))
})
const logoSvg = Buffer.from(
getSimpleIcon({ name: 'npm' }).replace('data:image/svg+xml;base64,', ''),
'base64',