Maybe a dumb question, but I just upgraded the npm package from 1.3.0 to 2.0.0 and previously did not use badge.loadFont:
const badge = require("gh-badges"),
badge(
{
text: ["storybook", "up to date"],
colorscheme: "orange",
template: "flat"
},
function(svg, err) {
fs.writeFileSync(folder + outputFile, svg);
}
);
Following the instructions here, I updated to:
const { BadgeFactory } = require("gh-badges");
const bf = new BadgeFactory();
const format = {
text: ["storybook", "up to date"],
colorscheme: "orange",
template: "flat"
};
const svg = bf.create(format);
Which produces this error:
TypeError: Cannot destructure propertyfontPathof 'undefined' or 'null'.
I'm not sure how the old code worked, but it clearly did not require a font path before. How can I use badges without a font path like I previously did?
Prior to 1.3.0 it looks like the interface looked like this:
var badge = require('gh-badges');
badge({ text: [ "build", "passed" ], colorscheme: "green" },
function(svg, err) {
// svg is a String… of your badge.
});
It looked for Verdana.ttf in the directory containing Shields for accurate width computation, and if it didn't find it, would fall back to Helvetica-Bold for approximate widths.
1.3.0 added an optional step, allowing you to specify the path to Verdana:
// Optional step, to have accurate text width computation.
badge.loadFont('/path/to/Verdana.ttf', function(err) {
badge({ text: ["build", "passed"], colorscheme: "green", template: "flat" },
function(svg, err) {
// svg is a String of your badge.
});
});
In 2.0.0 there is no default font path. If you want to use Helvetica, you can pass 'Helvetica' for either fontPath or defaultFontPath:
const bf = new BadgeFactory({ fallbackFontPath: 'Helvetica' });
We could make that the default in 2.1.0. Though I've also proposed a change in #2311 that will eliminate the need for fonts entirely, which is probably a better path.
Thank you! I was going crazy thinking I had to have a local font file or something. Worked like a charm.
This information has been added to the changelog in #2300.