reuse variable names instead of the names I had guessed

This commit is contained in:
m5r 2023-02-15 19:40:00 +01:00
parent 36fb23677a
commit 75c5fc0841
No known key found for this signature in database
GPG Key ID: 5BC847276DD5DDEA

View File

@ -29,24 +29,28 @@ const languageFontMap = {
math: "Noto+Sans+Math",
unknown: "Noto+Sans",
};
async function loadGoogleFont(fontFamily: string | string[], segment: string) {
if (!fontFamily || !segment) {
async function loadGoogleFont(fontFamily: string | string[], text: string) {
if (!fontFamily || !text) {
return;
}
let o = `https://fonts.googleapis.com/css2?family=${fontFamily}&text=${encodeURIComponent(segment)}`,
s = (
await (
await fetch(o, {
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",
},
})
).text()
).match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
if (!s) throw new Error("Failed to load font");
return fetch(s[1]).then((a) => a.arrayBuffer());
const API = `https://fonts.googleapis.com/css2?family=${fontFamily}&text=${encodeURIComponent(text)}`;
const css = (
await (
await fetch(API, {
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",
},
})
).text()
);
const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
if (!resource) {
throw new Error("Failed to load font");
}
return fetch(resource[1]).then((res) => res.arrayBuffer());
}
const assetCache = new Map();
const loadDynamicAsset = (emojiType?: EmojiType) => {