Skip to content

6.3.0

Choose a tag to compare

@20syldev 20syldev released this 15 Nov 20:04
· 44 commits to master since this release
6.3.0
f6fc2f4

Feature release for moxon API: a new endpoint, GET /v6/badge, draws a customizable pill badge as an SVG image, ready to be dropped in a README or a web page with a plain <img>. Nothing else changes: the other endpoints, v4 and v5 behave exactly as in 6.2.0.

Badge

  • GET /v6/badge?label={text} — only the label is required. The response is a standalone image/svg+xml picture with a rounded gradient background, an optional icon before the label and another after it, and it is sent with Cache-Control: public, max-age=86400 and a Content-Security-Policy: default-src 'none' header. On v4 and v5 it answers the usual 404 (Endpoint not available in v4.).
  • Colors — start and end set the gradient (#2d333b by default, end defaults to start), ink the text and icon color (#ffffff), and border adds a 1 px outline. Colors are hex values with or without the #, in the ff6600 or f60 form.
  • Icons — icon and trail pick one of 105 bundled Lucide icons, such as rocket, tag, github, shield-check or arrow-right, plus a filled discord logo. An unknown name is refused with Unknown icon "name".
  • Two parts — add a message to get a two-part badge like the ones of shields.io: the label on the left with start, end and ink, the message on the right with messageStart (#0969da), messageEnd and messageInk. The title and the accessible name read label: message.
  • Shape — size is xs, sm (default), md or lg, from 16 to 28 px tall. radius goes from 0 for square corners up to the full pill, which is the default, and angle (0 to 360, the CSS convention: 90 runs left to right, 180 top to bottom, 135 is the default corner-to-corner gradient) turns the gradient. lift (0 to 10) adds transparent space under the badge, to sit it higher next to text with align="absmiddle".
  • Font — font is sans (default), serif or mono, and weight is bold (default) or normal. The text is measured with the metrics of DejaVu and the badge is drawn with the first matching font installed on the viewer's system, so another family only changes the letter spacing slightly.
  • Limits and errors — a label or a message holds at most 64 characters. Control, invisible and bidirectional characters are refused, accents are composed, and runs of spaces collapse into one. lift, radius and angle take a plain decimal number with at most two decimals (0x5, 1e1 or an empty value are refused). Every invalid value answers 400 with a message that names it, such as Invalid size (use xs, sm, md or lg).

Package

  • Icons and licences — the bundled icons come from Lucide 0.562.0 (ISC licence, with portions under the MIT licence of Feather), and their notices are kept in the source. The width tables used to measure the text are plain numeric metrics read from DejaVu.
  • badge export — the function behind the route is also exported from @moxon/api and @moxon/api/v6. It takes an options object (label and the parameters above, with lift, radius and angle as numbers) and returns { contentType, body }, or throws an Error with the message of the 400. @moxon/api/v4 and @moxon/api/v5 do not have it.