diff --git a/README.md b/README.md index 22ed0d8..94dcd8d 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ async function handler(req: Request) { serve(handler); ``` -Then run `deno run --allow-net=:8000 --allow-env og.tsx` +Then run `deno run --allow-net=:8000,fonts.googleapis.com,fonts.gstatic.com,cdn.jsdelivr.net --allow-env og.tsx` Read more about the API, supported features and check out the examples in the following sections. diff --git a/emoji.ts b/emoji.ts index 5bf3f66..96dadaf 100644 --- a/emoji.ts +++ b/emoji.ts @@ -1,6 +1,6 @@ const apis = { twemoji: (code: string) => - "https://twemoji.maxcdn.com/v/latest/svg/" + code.toLowerCase() + ".svg", + "https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/" + code.toLowerCase() + ".svg", openmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/openmoji@2.0.0/svg/", blobmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/blob@2.0.0/svg/", noto: diff --git a/mod.ts b/mod.ts index 67ea656..88aa096 100644 --- a/mod.ts +++ b/mod.ts @@ -1,8 +1,8 @@ import type { ReactElement } from "https://esm.sh/react@18.2.0"; -import type { SatoriOptions } from "https://esm.sh/satori@0.0.40"; +import type { SatoriOptions } from "https://esm.sh/satori@0.0.46"; -import satori, { init as initSatori } from "https://esm.sh/satori@0.0.40/wasm"; -import { initStreaming } from "https://esm.sh/yoga-wasm-web@0.1.2"; +import satori, { init as initSatori } from "https://esm.sh/satori@0.0.46/wasm"; +import { initStreaming } from "https://esm.sh/yoga-wasm-web@0.3.0"; import { initWasm, @@ -28,15 +28,15 @@ declare module "https://esm.sh/react@18.2.0" { } const resvg_wasm = fetch( - "https://unpkg.com/@vercel/og@0.0.18/vendor/resvg.simd.wasm", + "https://cdn.jsdelivr.net/npm/@vercel/og@0.0.25/vendor/resvg.simd.wasm", ).then((res) => res.arrayBuffer()); const yoga_wasm = fetch( - "https://unpkg.com/@vercel/og@0.0.18/vendor/yoga.wasm", + "https://cdn.jsdelivr.net/npm/@vercel/og@0.0.25/vendor/yoga.wasm", ); const fallbackFont = fetch( - "https://unpkg.com/@vercel/og@0.0.18/vendor/noto-sans-v27-latin-regular.ttf", + "https://cdn.jsdelivr.net/npm/@vercel/og@0.0.25/vendor/noto-sans-v27-latin-regular.ttf", ).then((a) => a.arrayBuffer()); const initializedResvg = initWasm(resvg_wasm); @@ -89,21 +89,28 @@ type ImageResponseOptions = ConstructorParameters[1] & { // than built-in. // @TODO: Cover most languages with Noto Sans. const languageFontMap = { - zh: "Noto+Sans+SC", - ja: "Noto+Sans+JP", - ko: "Noto+Sans+KR", - th: "Noto+Sans+Thai", - he: "Noto+Sans+Hebrew", - ar: "Noto+Sans+Arabic", - bn: "Noto+Sans+Bengali", - ta: "Noto+Sans+Tamil", - te: "Noto+Sans+Telugu", - ml: "Noto+Sans+Malayalam", + "ja-JP": "Noto+Sans+JP", + "ko-KR": "Noto+Sans+KR", + "zh-CN": "Noto+Sans+SC", + "zh-TW": "Noto+Sans+TC", + "zh-HK": "Noto+Sans+HK", + "th-TH": "Noto+Sans+Thai", + "bn-IN": "Noto+Sans+Bengali", + "ar-AR": "Noto+Sans+Arabic", + "ta-IN": "Noto+Sans+Tamil", + "ml-IN": "Noto+Sans+Malayalam", + "he-IL": "Noto+Sans+Hebrew", + "te-IN": "Noto+Sans+Telugu", devanagari: "Noto+Sans+Devanagari", + kannada: "Noto+Sans+Kannada", + symbol: ["Noto+Sans+Symbols", "Noto+Sans+Symbols+2"], + math: "Noto+Sans+Math", unknown: "Noto+Sans", }; -async function loadGoogleFont(font: string, text: string) { +async function loadGoogleFont(fonts: string | string[], text: string) { + // @TODO: Support multiple fonts. + const font = Array.isArray(fonts) ? fonts.at(-1) : fonts; if (!font || !text) return; const API = `https://fonts.googleapis.com/css2?family=${font}&text=${