All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1011 B
TypeScript
37 lines
1011 B
TypeScript
// Pinned Twemoji release.
|
|
const TWEMOJI_VERSION = "16.0.1";
|
|
|
|
// Cache the fetched glyph per emoji so repeated runs don't re-hit the network.
|
|
const glyphCache = new Map<string, string>();
|
|
|
|
/**
|
|
* Twemoji's plain vector-path SVG for `emoji`, whose file is named `cp` (see
|
|
* emojiToCodepoint in lib/site-icons.ts).
|
|
*/
|
|
export async function fetchTwemojiSvg(
|
|
emoji: string,
|
|
cp: string,
|
|
): Promise<string> {
|
|
const cached = glyphCache.get(cp);
|
|
if (cached) return cached;
|
|
const url =
|
|
`https://cdn.jsdelivr.net/gh/jdecked/twemoji@${TWEMOJI_VERSION}/assets/svg/${cp}.svg`;
|
|
let res: Response;
|
|
try {
|
|
res = await fetch(url);
|
|
} catch (cause) {
|
|
throw new Error(
|
|
`Failed to fetch Twemoji glyph for "${emoji}" (${cp}) from ${url}`,
|
|
{ cause },
|
|
);
|
|
}
|
|
if (!res.ok) {
|
|
throw new Error(
|
|
`Failed to fetch Twemoji glyph for "${emoji}" (${cp}) from ${url}: ${res.status} ${res.statusText}`,
|
|
);
|
|
}
|
|
const svg = await res.text();
|
|
glyphCache.set(cp, svg);
|
|
return svg;
|
|
}
|