reuse variable names instead of the names I had guessed
This commit is contained in:
parent
36fb23677a
commit
75c5fc0841
20
src/index.ts
20
src/index.ts
@ -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 = (
|
||||
const API = `https://fonts.googleapis.com/css2?family=${fontFamily}&text=${encodeURIComponent(text)}`;
|
||||
const css = (
|
||||
await (
|
||||
await fetch(o, {
|
||||
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()
|
||||
).match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
|
||||
if (!s) throw new Error("Failed to load font");
|
||||
return fetch(s[1]).then((a) => a.arrayBuffer());
|
||||
);
|
||||
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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user