Make webfont formats customizable (#1266).

This commit is contained in:
be5invis 2021-12-22 19:51:58 -08:00
parent 4b38956104
commit c2c903ebce
5 changed files with 22 additions and 16 deletions

View file

@ -2,11 +2,18 @@
const fs = require("fs");
const WebfontFormatMap = new Map([
["woff2", "woff2"],
["ttf", "truetype"]
]);
module.exports = function (output, family, hs, formats) {
let ans = ``;
for (const ext of formats) {
if (!WebfontFormatMap.get(ext)) throw new TypeError("Invalid webfont file format " + ext);
}
for (const term of hs) {
let src = formats
.map(([ext, format]) => `url('${ext}/${term.name}.${ext}') format('${format}')`)
const src = formats
.map(ext => `url('${ext}/${term.name}.${ext}') format('${WebfontFormatMap.get(ext)}')`)
.join(", ");
ans += `
@font-face {