Skip to content

Commit

Permalink
Merge pull request #3 from aaharu/update-dependencies
Browse files Browse the repository at this point in the history
chore: update to the latest version of satori
  • Loading branch information
ascorbic committed Jan 10, 2023
2 parents 85805c0 + 7f19432 commit da90a5a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion emoji.ts
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
41 changes: 24 additions & 17 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -89,21 +89,28 @@ type ImageResponseOptions = ConstructorParameters<typeof Response>[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=${
Expand Down

0 comments on commit da90a5a

Please sign in to comment.