fix font
This commit is contained in:
parent
0b1dcf165f
commit
49cabb5a25
|
|
@ -31,21 +31,29 @@ export const _ = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let f: Response = null as any;
|
let f: Response = null as any;
|
||||||
|
let raw = false;
|
||||||
if (pathname?.startsWith("/s/")) {
|
if (pathname?.startsWith("/s/")) {
|
||||||
f = await fetch(`https://fonts.gstatic.com${pathname}`);
|
f = await fetch(`https://fonts.gstatic.com${pathname}`);
|
||||||
|
raw = true;
|
||||||
} else {
|
} else {
|
||||||
f = await fetch(`https://fonts.googleapis.com${pathname}`);
|
f = await fetch(`https://fonts.googleapis.com${pathname}`);
|
||||||
}
|
}
|
||||||
if (f) {
|
if (f) {
|
||||||
const body = await f.text();
|
let body = null as any;
|
||||||
|
|
||||||
|
if (!raw) {
|
||||||
|
body = await f.text();
|
||||||
|
body = body.replaceAll("https://fonts.gstatic.com", "/_font");
|
||||||
|
} else {
|
||||||
|
body = await f.arrayBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
g._font_cache[pathname] = { body, headers: {} };
|
g._font_cache[pathname] = { body, headers: {} };
|
||||||
f.headers.forEach((v, k) => {
|
f.headers.forEach((v, k) => {
|
||||||
g._font_cache[pathname].headers[k] = v;
|
g._font_cache[pathname].headers[k] = v;
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = new Response(
|
const res = new Response(body);
|
||||||
body.replaceAll("https://fonts.gstatic.com", "/_font")
|
|
||||||
);
|
|
||||||
|
|
||||||
res.headers.set("content-type", f.headers.get("content-type") || "");
|
res.headers.set("content-type", f.headers.get("content-type") || "");
|
||||||
return res;
|
return res;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ export const prodIndex = (
|
||||||
<meta name="viewport"
|
<meta name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, user-scalable=1.0, minimum-scale=1.0, maximum-scale=1.0">
|
content="width=device-width, initial-scale=1.0, user-scalable=1.0, minimum-scale=1.0, maximum-scale=1.0">
|
||||||
<link rel="stylesheet" href="/index.css">
|
<link rel="stylesheet" href="/index.css">
|
||||||
|
<style>
|
||||||
|
@import url('/_font/css2?family=Source+Sans+3:wght@400;600&display=swap');
|
||||||
|
</style>
|
||||||
${this.head.join("\n")}
|
${this.head.join("\n")}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -240,7 +240,7 @@ export const PanelFont: FC<{
|
||||||
const doc = document;
|
const doc = document;
|
||||||
let weight = `:wght@${[300, 400, 500, 600].join(";")}`;
|
let weight = `:wght@${[300, 400, 500, 600].join(";")}`;
|
||||||
let fontName = item.value.replace(/ /g, "+");
|
let fontName = item.value.replace(/ /g, "+");
|
||||||
const _href = `https://api.fonts.coollabs.io/css2?family=${fontName}${weight}`;
|
const _href = `/_font/css2?family=${fontName}${weight}`;
|
||||||
if (!doc.querySelector(`link[href="${_href}]`)) {
|
if (!doc.querySelector(`link[href="${_href}]`)) {
|
||||||
const link = doc.createElement("link");
|
const link = doc.createElement("link");
|
||||||
link.type = "text/css";
|
link.type = "text/css";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue