From d0e299a2e76064674e2069c354df560e010d9972 Mon Sep 17 00:00:00 2001 From: enneaa Date: Wed, 2 Apr 2025 22:10:49 +0800 Subject: [PATCH] Update emoji.ts --- quartz/util/emoji.ts | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/quartz/util/emoji.ts b/quartz/util/emoji.ts index 4d3434f60..e38618d1d 100644 --- a/quartz/util/emoji.ts +++ b/quartz/util/emoji.ts @@ -25,23 +25,14 @@ function toCodePoint(unicodeSurrogates: string) { return r.join("-") } -type EmojiMap = { - codePointToName: Record - nameToBase64: Record -} - -let emojimap: EmojiMap | undefined = undefined -export async function loadEmoji(code: string) { - if (!emojimap) { - const data = await import("./emojimap.json") - emojimap = data - } - - const name = emojimap.codePointToName[`U+${code.toUpperCase()}`] - if (!name) throw new Error(`codepoint ${code} not found in map`) - - const b64 = emojimap.nameToBase64[name] - if (!b64) throw new Error(`name ${name} not found in map`) - - return b64 +const twemoji = (code: string) => + `https://cdnjs.cloudflare.com/ajax/libs/twemoji/15.1.0/svg/${code.toLowerCase()}.svg` +const emojiCache: Record> = {} + +export function loadEmoji(code: string) { + const type = "twemoji" + const key = type + ":" + code + if (key in emojiCache) return emojiCache[key] + + return (emojiCache[key] = fetch(twemoji(code)).then((r) => r.text())) }