Hacker News new | ask | show | jobs
by cuu508 2421 days ago
I went more minimalistic and added SVG badge support in the form of a Django template and a couple small python functions.

The template: https://raw.githubusercontent.com/healthchecks/healthchecks/...

And the function for rendering the template: https://github.com/healthchecks/healthchecks/blob/master/hc/...

One funky thing there is the measurement of text width. The width of the badge depends of the width of the text you put into it. I simply measured the width of each individual alphabet letter, and use that to calculate the width of a string. It's not super accurate, but works fine in practice. It was a fun weekend project.

1 comments

Nice! My approach is very similar except that I have width mappings for non-ASCII characters. Also, since DejaVu Sans (the font that shield.io, pybadges and healthchecks use) is heavily kerned, I have a table of kerning widths.

You can also opt to use precise text width measurements (important for Arabic, Chinese, etc.) but then you have to have the font file available on your system.