fix: render correctly with iconWidth

pull/21/head
Amio 2018-08-31 13:34:36 +08:00
rodzic fdb64c2618
commit 025adb12a1
7 zmienionych plików z 42 dodań i 33 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ module.exports = ({ subject, status, color, style, icon, iconWidth = 13 }) => {
iconWidth = iconWidth * 10
const iconSpanWidth = icon ? (subject.length ? iconWidth + 30 : iconWidth - 18) : 0
const sbTextStart = icon ? (iconSpanWidth + 50) : 50
const sbTextWidth = calcWidth(subject)
const stTextWidth = calcWidth(status)
const sbRectWidth = sbTextWidth + 100 + iconSpanWidth
@ -26,8 +27,8 @@ module.exports = ({ subject, status, color, style, icon, iconWidth = 13 }) => {
<rect fill="#${color}" x="${sbRectWidth}" width="${stRectWidth}" height="200"/>
</g>
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
<text x="${icon ? '220' : '50'}" y="148" textLength="${sbTextWidth}" fill="#000" opacity="0.1">${subject}</text>
<text x="${icon ? '210' : '50'}" y="138" textLength="${sbTextWidth}">${subject}</text>
<text x="${sbTextStart + 10}" y="148" textLength="${sbTextWidth}" fill="#000" opacity="0.1">${subject}</text>
<text x="${sbTextStart}" y="138" textLength="${sbTextWidth}">${subject}</text>
<text x="${sbRectWidth + 55}" y="148" textLength="${stTextWidth}" fill="#000" opacity="0.1">${status}</text>
<text x="${sbRectWidth + 45}" y="138" textLength="${stTextWidth}">${status}</text>
</g>
@ -47,8 +48,8 @@ module.exports = ({ subject, status, color, style, icon, iconWidth = 13 }) => {
<rect width="${width}" height="200" fill="url(#a)"/>
</g>
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
<text x="${icon ? '220' : '60'}" y="148" textLength="${sbTextWidth}" fill="#000" opacity="0.25">${subject}</text>
<text x="${icon ? '210' : '50'}" y="138" textLength="${sbTextWidth}">${subject}</text>
<text x="${sbTextStart + 10}" y="148" textLength="${sbTextWidth}" fill="#000" opacity="0.25">${subject}</text>
<text x="${sbTextStart}" y="138" textLength="${sbTextWidth}">${subject}</text>
<text x="${sbRectWidth + 55}" y="148" textLength="${stTextWidth}" fill="#000" opacity="0.25">${status}</text>
<text x="${sbRectWidth + 45}" y="138" textLength="${stTextWidth}">${status}</text>
</g>

Wyświetl plik

@ -44,9 +44,11 @@
| Badge | URL |
| --- | --- |
| ![](http://localhost:3000//badge?icon=1) | [//badge?icon=1](http://localhost:3000//badge?icon=1)
| ![](/icon/badge?icon=1) | [/icon/badge?icon=1](/icon/badge?icon=1)
| ![](/icon/badge?icon=1&style=flat) | [/icon/badge?icon=1&style=flat](/icon/badge?icon=1&style=flat)
| ![](http://localhost:3000//badge?icon=chrome) | [//badge?icon=chrome](http://localhost:3000//badge?icon=chrome)
| ![](/icon/badge?icon=chrome) | [/icon/badge?icon=chrome](/icon/badge?icon=chrome)
| ![](/icon/badge?icon=chrome&style=flat) | [/icon/badge?icon=chrome&style=flat](/icon/badge?icon=chrome&style=flat)
| ![](/icon/badge?icon=lgtm&iconWidth=19&style=flat) | [/icon/badge?icon=lgtm&iconWidth=19&style=flat](/icon/badge?icon=lgtm&iconWidth=19&style=flat)
## Edge Cases

Wyświetl plik

@ -5,17 +5,17 @@ const qs = require('querystring')
const serveMarked = require('serve-marked')
const badgen = require('..')
const iconDataURI = require('../test/icon-data-uri.js')
const icons = require('../test/icon-data-uri.js')
const serveBadge = (req, res) => {
const { pathname, query } = url.parse(req.url)
const { style, icon } = qs.parse(query)
const { style, icon, iconWidth } = qs.parse(query)
const [ subject, status, color ] = pathname.split('/').splice(1)
.map(s => qs.unescape(s))
res.statusCode = 200
res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
res.end(badgen({ subject, status, color, style, icon: icon && iconDataURI }))
res.end(badgen({ subject, status, color, style, icon: icons[icon], iconWidth }))
}
const md = path.join(__dirname, 'preview.md')

Wyświetl plik

@ -56,7 +56,7 @@ exports[`test/index.spec.js TAP generate badge with { subject, status, style } >
<rect fill="#08C" x="349" width="455" height="200"/>
</g>
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
<text x="50" y="148" textLength="249" fill="#000" opacity="0.1">npm</text>
<text x="60" y="148" textLength="249" fill="#000" opacity="0.1">npm</text>
<text x="50" y="138" textLength="249">npm</text>
<text x="404" y="148" textLength="355" fill="#000" opacity="0.1">v1.0.0</text>
<text x="394" y="138" textLength="355">v1.0.0</text>
@ -72,7 +72,7 @@ exports[`test/index.spec.js TAP generate badge with { subject, status, color, st
<rect fill="#ADF" x="349" width="455" height="200"/>
</g>
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
<text x="50" y="148" textLength="249" fill="#000" opacity="0.1">npm</text>
<text x="60" y="148" textLength="249" fill="#000" opacity="0.1">npm</text>
<text x="50" y="138" textLength="249">npm</text>
<text x="404" y="148" textLength="355" fill="#000" opacity="0.1">v1.0.0</text>
<text x="394" y="138" textLength="355">v1.0.0</text>
@ -116,8 +116,8 @@ exports[`test/index.spec.js TAP generate badge with { status, icon } > snapshot
<rect width="536" height="200" fill="url(#a)"/>
</g>
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
<text x="220" y="148" textLength="0" fill="#000" opacity="0.25"></text>
<text x="210" y="138" textLength="0"></text>
<text x="172" y="148" textLength="0" fill="#000" opacity="0.25"></text>
<text x="162" y="138" textLength="0"></text>
<text x="267" y="148" textLength="224" fill="#000" opacity="0.25">icon</text>
<text x="257" y="138" textLength="224">icon</text>
</g>
@ -126,24 +126,24 @@ exports[`test/index.spec.js TAP generate badge with { status, icon } > snapshot
`
exports[`test/index.spec.js TAP generate badge with { status, icon, iconWidth } > snapshot 1`] = `
<svg width="55.6" height="20" viewBox="0 0 556 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg width="59.6" height="20" viewBox="0 0 596 200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<linearGradient id="a" x2="0" y2="100%">
<stop offset="0" stop-opacity=".1" stop-color="#EEE"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="m"><rect width="556" height="200" rx="30" fill="#FFF"/></mask>
<mask id="m"><rect width="596" height="200" rx="30" fill="#FFF"/></mask>
<g mask="url(#m)">
<rect width="232" height="200" fill="#555"/>
<rect width="324" height="200" fill="#08C" x="232"/>
<rect width="556" height="200" fill="url(#a)"/>
<rect width="272" height="200" fill="#555"/>
<rect width="324" height="200" fill="#08C" x="272"/>
<rect width="596" height="200" fill="url(#a)"/>
</g>
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
<text x="220" y="148" textLength="0" fill="#000" opacity="0.25"></text>
<text x="210" y="138" textLength="0"></text>
<text x="287" y="148" textLength="224" fill="#000" opacity="0.25">icon</text>
<text x="277" y="138" textLength="224">icon</text>
<text x="232" y="148" textLength="0" fill="#000" opacity="0.25"></text>
<text x="222" y="138" textLength="0"></text>
<text x="327" y="148" textLength="224" fill="#000" opacity="0.25">icon</text>
<text x="317" y="138" textLength="224">icon</text>
</g>
<image x="40" y="35" width="150" height="130" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9IiNGRkYiIHZpZXdCb3g9IjAgMCAyNCAyNCI+CiAgPHBhdGggZD0iTTE2LjIxIDguNjlsNi43Mi0xLjY4QTEyLjAzIDEyLjAzIDAgMCAxIDI0IDExLjk3YTEyLjA5IDEyLjA5IDAgMCAxLTEyLjk0IDEybDQuOS04LjM1Yy4zNi0uMzguNjYtLjguODktMS4yN2E1LjQ1IDUuNDUgMCAwIDAtLjA1LTQuNzUgNS4xNiA1LjE2IDAgMCAwLS41OS0uOTF6bS0zLjI0IDguNTdsLTIuMTIgNi42OUExMi4wMiAxMi4wMiAwIDAgMSAyLjA0IDUuMjhsNC44MyA4LjM4Yy4xOC41NCAx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9zdmc+"/>
</svg>
`
@ -159,6 +159,6 @@ exports[`test/index.spec.js TAP generate badge with { subject, status, icon, sty
<text x="686" y="148" textLength="224" fill="#000" opacity="0.1">icon</text>
<text x="676" y="138" textLength="224">icon</text>
</g>
<image x="40" y="35" width="130" height="132" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9IiNGRkYiIHZpZXdCb3g9IjAgMCAyNCAyNCI+CiAgPHBhdGggZD0iTTE2LjIxIDguNjlsNi43Mi0xLjY4QTEyLjAzIDEyLjAzIDAgMCAxIDI0IDExLjk3YTEyLjA5IDEyLjA5IDAgMCAxLTEyLjk0IDEybDQuOS04LjM1Yy4zNi0uMzguNjYtLjguODktMS4yN2E1LjQ1IDUuNDUgMCAwIDAtLjA1LTQuNzUgNS4xNiA1LjE2IDAgMCAwLS41OS0uOTF6bS0zLjI0IDguNTdsLTIuMTIgNi42OUExMi4wMiAxMi4wMiAwIDAgMSAyLjA0IDUuMjhsNC44MyA4LjM4Yy4xOC41NCAxLjEyIDIuNTggMy4wNyAzLjMyIDEgLjM5IDIuMDQuNDggMy4wMy4yOXptLTEtOS42NGE0LjUyIDQuNTIgMCAwIDAtNC4yOCAzLjUxIDQuNDggNC40OCAwIDAgMCAxLjI0IDQuMDMgNC40OSA0LjQ5IDAgMCAwIDQuNzMuOTMgNC40OSA0LjQ5IDAgMCAwIDIuNy0zLjQzIDQuNTMgNC41MyAwIDAgMC0yLjUtNC42MyA0LjQxIDQuNDEgMCAwIDAtMS44OS0uNDF6TTcuMDUgOS45NmwtNC44LTVBMTIuMDQgMTIuMDQgMCAwIDEgMTIgMGM0LjU2IDAgOC43NCAyLjYgMTAuNzcgNi42N0gxMi41NmE1LjU0IDUuNTQgMCAwIDAtNC4yNyAxLjQ2IDUuMzQgNS4zNCAwIDAgMC0xLjI0IDEuODN6Ii8+Cjwvc3ZnPgo="/>
<image x="40" y="35" width="130" height="132" xlink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DYgNi40NGE1LjEgNS4xIDAgMCAxIDAgMTAuMTk3IDUuMDk4IDUuMDk4IDAgMCAxLTQuOTM4LTYuMzY3IDIuMTQ0IDIuMTQ0IDAgMSAwIDIuMDc0LTIuOTUgNS4wNzIgNS4wNzIgMCAwIDEgMi44NjQtLjg4em0tMjcuNTI1LTYuNDRjLTYuMzM2IDAtMTEuNDcyIDUuMTM3LTExLjQ3MiAxMS40NzMgMCA2LjMzNiA1LjEzNiAxMS40NzMgMTEuNDcyIDExLjQ3MyA2LjMzNiAwIDExLjQ3My01LjEzNyAxMS40NzMtMTEuNDczIDAtNi4zMzYtNS4xMzctMTEuNDczLTExLjQ3My0xMS40NzN6bTEuNjQgNi40NGE1LjEgNS4xIDAgMCAxIDAgMTAuMTk3IDUuMDk4IDUuMDk4IDAgMCAxLTQuOTM4LTYuMzY3IDIuMTQ0IDIuMTQ0IDAgMCAwIDQuMTI3LS44MSAyLjE0MiAyLjE0MiAwIDAgMC0yLjA1NC0yLjE0IDUuMDc0IDUuMDc0IDAgMCAxIDIuODY0LS44OHoiLz48L2c+PC9zdmc+"/>
</svg>
`

Wyświetl plik

@ -1,7 +1,12 @@
const fs = require('fs')
const path = require('path')
const iconSVG = fs.readFileSync(path.join(__dirname, 'chrome.svg'))
const iconDataURI = 'data:image/svg+xml;base64,' + iconSVG.toString('base64')
const readAsDataURI = file => {
const svg = fs.readFileSync(path.join(__dirname, file))
return `data:image/svg+xml;base64,${svg.toString('base64')}`
}
module.exports = iconDataURI
module.exports = {
chrome: readAsDataURI('chrome.svg'),
lgtm: readAsDataURI('lgtm.svg')
}

Wyświetl plik

@ -1,6 +1,6 @@
const tap = require('tap')
const badgen = require('..')
const icon = require('./icon-data-uri.js')
const icons = require('./icon-data-uri.js')
tap.test('generate badge with { subject, status }', t => {
const svg = badgen({ subject: 'npm', status: 'v1.0.0' })
@ -31,25 +31,25 @@ tap.test('generate badge with { subject, status, color, style }', t => {
})
tap.test('generate badge with { subject, status, icon }', t => {
const svg = badgen({ subject: 'docker', status: 'icon', icon })
const svg = badgen({ subject: 'docker', status: 'icon', icon: icons.chrome })
t.matchSnapshot(svg, 'snapshot')
t.end()
})
tap.test('generate badge with { status, icon }', t => {
const svg = badgen({ subject: '', status: 'icon', icon })
const svg = badgen({ subject: '', status: 'icon', icon: icons.chrome })
t.matchSnapshot(svg, 'snapshot')
t.end()
})
tap.test('generate badge with { status, icon, iconWidth }', t => {
const svg = badgen({ subject: '', status: 'icon', icon, iconWidth: 15 })
const svg = badgen({ subject: '', status: 'icon', icon: icons.lgtm, iconWidth: 19 })
t.matchSnapshot(svg, 'snapshot')
t.end()
})
tap.test('generate badge with { subject, status, icon, style }', t => {
const svg = badgen({ subject: 'docker', status: 'icon', style: 'flat', icon })
const svg = badgen({ subject: 'docker', status: 'icon', style: 'flat', icon: icons.lgtm })
t.matchSnapshot(svg, 'snapshot')
t.end()
})

1
test/lgtm.svg 100644
Wyświetl plik

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="340.925" height="202.676" viewBox="0 0 90.203 53.625"><g fill="#fff"><path opacity=".456" d="M45.216 3.826c-12.836 0-22.28 3.634-26.884 10.531-.091-.106-.171-.172-.266-.302-.459-.629-.945-1.486-1.428-2.384-.484-.898-.967-1.835-1.485-2.67-.518-.835-1.025-1.593-1.874-2.116-.927-.573-1.733-.828-2.347-.916a3.683 3.683 0 0 0-.862-.015c-1.535.006-2.714 1.018-3.62 2.255-.91 1.241-1.609 2.835-2.042 4.586-.866 3.499-.703 7.758 2.056 10.56 1.46 1.493 3.404 2.35 5.265 2.85 1.32.355 2.53.478 3.629.509.608 7.133 4.797 13.406 10.39 16.559h.001c2.985 1.677 6.084 2.538 8.799 3.577 3.468 1.34 6.834 2.643 10.366 2.952l.058.006h.405c3.705 0 7.076-1.656 10.478-2.956 2.71-1.037 5.812-1.876 8.802-3.556 5.623-3.152 9.81-9.44 10.42-16.572 2.678-.052 6.356-.828 8.841-3.367 2.761-2.802 2.925-7.062 2.058-10.562-.433-1.75-1.131-3.345-2.041-4.586-.907-1.237-2.086-2.25-3.621-2.255a3.684 3.684 0 0 0-.862.015c-.614.088-1.42.343-2.348.916-.844.52-1.35 1.273-1.865 2.102-.516.83-.997 1.76-1.478 2.655-.48.894-.964 1.75-1.42 2.382-.094.13-.174.197-.264.303-4.611-6.87-14.045-10.5-26.86-10.5z"/><path d="M45.13 0C34.178 0 24.922 2.551 18.84 7.928c-.184-.327-.319-.61-.53-.949-.636-1.025-1.231-2.189-3.11-3.347-1.331-.823-2.657-1.282-3.81-1.45-.574-.082-1.242-.055-1.768-.007l.371-.047c-3.417 0-5.421 2.05-6.718 3.818C1.98 7.715 1.145 9.7.607 11.872c-1.075 4.343-1.088 9.965 3.04 14.16 2.164 2.208 4.706 3.244 7.005 3.86.443.118.837.148 1.262.236 1.499 7.11 5.936 13.123 11.87 16.467l.002.003.004.001c3.491 1.962 6.806 2.86 9.29 3.81 3.476 1.34 7.14 2.823 11.413 3.197l.224.02h.567c4.905 0 8.627-1.982 11.846-3.212h.002c2.46-.942 5.788-1.814 9.305-3.79a23.139 23.139 0 0 0 4.498-3.309 25.403 25.403 0 0 0 7.392-12.962c2.727-.466 5.62-1.66 8.23-4.323 4.126-4.194 4.114-9.816 3.04-14.158-.539-2.172-1.373-4.157-2.67-5.926-1.296-1.769-3.3-3.818-6.717-3.818l.378.048c-.53-.048-1.2-.076-1.775.007-1.152.168-2.473.628-3.8 1.448-1.873 1.154-2.47 2.315-3.105 3.336-.208.334-.34.613-.522.936C65.306 2.546 56.065 0 45.13 0zm.087 5.15c13.369 0 22.602 4.003 26.526 11.165 2.364-.917 4.107-7.105 6.056-8.304 1.578-.976 2.501-.735 2.501-.735 3.571 0 7.25 10.513 2.675 15.154-2.418 2.471-6.881 3.165-9.104 2.988-.168 7.163-4.341 13.63-9.862 16.724-2.809 1.578-5.832 2.404-8.627 3.474-3.464 1.325-6.715 2.868-10.006 2.868h-.347c-3.277-.286-6.54-1.53-10.005-2.868-2.796-1.07-5.818-1.918-8.627-3.496-5.49-3.095-9.666-9.542-9.834-16.704-2.206.19-6.719-.497-9.155-2.986-4.574-4.64-.895-15.154 2.676-15.154 0 0 .923-.241 2.501.735 1.96 1.205 3.71 7.454 6.094 8.319C22.597 9.15 31.836 5.15 45.217 5.15z"/><path d="M47.14 40.99c.902 0 1.423-.584 1.423-1.373 0-1.239-.522-1.714-1.418-1.786-.32-.026-.584.065-.674.347-.09.282.054.633.347.674.686.097.685.216.685.566 0 .348-.402.494-.485.513a.536.536 0 0 0 .121 1.058m-3.833.001c-.902 0-1.423-.584-1.423-1.373 0-1.239.521-1.714 1.417-1.786.321-.026.584.065.675.347.09.282-.054.633-.347.674-.686.097-.686.216-.686.566 0 .348.403.494.486.513a.536.536 0 0 1-.122 1.058m16.476-27.081c-6.336 0-11.472 5.137-11.472 11.473 0 6.336 5.136 11.473 11.472 11.473 6.336 0 11.473-5.137 11.473-11.473 0-6.336-5.137-11.473-11.473-11.473zm-1.606 6.44a5.1 5.1 0 0 1 0 10.197 5.098 5.098 0 0 1-4.938-6.367 2.144 2.144 0 1 0 2.074-2.95 5.072 5.072 0 0 1 2.864-.88zm-27.525-6.44c-6.336 0-11.472 5.137-11.472 11.473 0 6.336 5.136 11.473 11.472 11.473 6.336 0 11.473-5.137 11.473-11.473 0-6.336-5.137-11.473-11.473-11.473zm1.64 6.44a5.1 5.1 0 0 1 0 10.197 5.098 5.098 0 0 1-4.938-6.367 2.144 2.144 0 0 0 4.127-.81 2.142 2.142 0 0 0-2.054-2.14 5.074 5.074 0 0 1 2.864-.88z"/></g></svg>

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 3.5 KiB