Failed to download dynamic font. Status: 400 #371
-
When running the "astro build" command, I encounter the error: The specific location is in the e.g. resource:
resource[1]:
When I request this URL directly in the browser, the same error occurs: This error also happens when building with Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
I temporarily circumvented this issue by using local font files. loadGoogleFont.ts import type { FontStyle, FontWeight } from "satori";
import * as fs from "fs";
import * as path from "path";
import { fileURLToPath, pathToFileURL } from "url";
export type FontOptions = {
name: string;
data: ArrayBuffer;
weight: FontWeight | undefined;
style: FontStyle | undefined;
};
// read font ArrayBuffer
function readFileAsArrayBuffer(filePath: string): Promise<ArrayBuffer> {
return new Promise((resolve, reject) => {
fs.readFile(filePath, (err, data) => {
if (err) {
reject(err);
} else {
resolve(
data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)
);
}
});
});
}
async function createFontOptionsByLocal(): Promise<
Array<{ name: string; data: ArrayBuffer; weight: number; style: string }>
> {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const fontPath1 = path.join(
__dirname,
"../../resources/",
"ibm-plex-mono-v19-latin-regular.ttf"
);
const fontPath2 = path.join(
__dirname,
"../../resources/",
"ibm-plex-mono-v19-latin-700.ttf"
);
const fontData1 = await readFileAsArrayBuffer(fontPath1);
const fontData2 = await readFileAsArrayBuffer(fontPath2);
return [
{ name: "IBM Plex Mono", weight: 400, style: "normal", data: fontData1 },
{ name: "IBM Plex Mono", weight: 700, style: "bold", data: fontData2 },
];
}
// export default loadGoogleFonts;
export default createFontOptionsByLocal; generate font file by https://gwfh.mranftl.com/fonts ibm-plex-mono-v19-latin-700.zip |
Beta Was this translation helpful? Give feedback.
-
Hello! |
Beta Was this translation helpful? Give feedback.
-
I found where the problem lies. The async function loadGoogleFont(
font: string,
text: string
) |
Beta Was this translation helpful? Give feedback.
-
The same problem, finally I chose a font that supports non-English characters, the problem is solved. const fontsConfig = [
{
name: "Noto Sans SC",
font: "Noto+Sans+SC",
weight: 400 as FontWeight,
style: "normal" as FontStyle,
},
{
name: "Noto Sans SC",
font: "Noto+Sans+SC:wght@700",
weight: 700 as FontWeight,
style: "normal" as FontStyle,
},
]; |
Beta Was this translation helpful? Give feedback.
The same problem, finally I chose a font that supports non-English characters, the problem is solved.