mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
fix: resolve non-latin char issue in generated OG images (#318)
Changes made - update font source with Google font - add error handling in font fetching logic - update docs in dynamic-og-images blog post --------- Co-authored-by: satnaing <satnaingdev@gmail.com>
This commit is contained in:
@@ -41,10 +41,48 @@ Dynamic OG images will be generated at build time for blog posts that
|
||||
Dynamic OG image of AstroPaper includes _the blog post title_, _author name_ and _site title_. Author name and site title will be retrieved via `SITE.author` and `SITE.title` of **"src/config.ts"** file. The title is generated from the blog post frontmatter `title`.
|
||||

|
||||
|
||||
### Issue Non-Latin Characters
|
||||
|
||||
Titles with non-latin characters won't display properly out of the box. To resolve this, we have to replace `fontsConfig` inside `loadGoogleFont.ts` with your preferred font.
|
||||
|
||||
```ts
|
||||
// file: loadGoogleFont.ts
|
||||
|
||||
async function loadGoogleFonts(
|
||||
text: string
|
||||
): Promise<
|
||||
Array<{ name: string; data: ArrayBuffer; weight: number; style: string }>
|
||||
> {
|
||||
const fontsConfig = [
|
||||
{
|
||||
name: "Noto Sans JP",
|
||||
font: "Noto+Sans+JP",
|
||||
weight: 400,
|
||||
style: "normal",
|
||||
},
|
||||
{
|
||||
name: "Noto Sans JP",
|
||||
font: "Noto+Sans+JP:wght@700",
|
||||
weight: 700,
|
||||
style: "normal",
|
||||
},
|
||||
{ name: "Noto Sans", font: "Noto+Sans", weight: 400, style: "normal" },
|
||||
{
|
||||
name: "Noto Sans",
|
||||
font: "Noto+Sans:wght@700",
|
||||
weight: 700,
|
||||
style: "normal",
|
||||
},
|
||||
];
|
||||
// other codes
|
||||
}
|
||||
```
|
||||
|
||||
> Check out [this PR](https://github.com/satnaing/astro-paper/pull/318) for more info.
|
||||
|
||||
## Limitations
|
||||
|
||||
At the time of writing this, [Satori](https://github.com/vercel/satori) is fairly new and has not reached major release yet. So, there are still some limitations to this dynamic OG image feature.
|
||||
|
||||
- If you have Blog posts with non-English titles, you have to set `embedFonts` option to `false` (file: `src/utils/generateOgImage.tsx`). Even after this, the OG image might not be displayed very well.
|
||||
- Besides, RTL languages are not supported yet.
|
||||
- [Using emoji](https://github.com/vercel/satori#emojis) in the title might be a little bit tricky.
|
||||
|
||||
Reference in New Issue
Block a user