mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-20 11:24:05 -06:00
Update emoji.ts
This commit is contained in:
parent
8aa2ee4a82
commit
d0e299a2e7
@ -25,23 +25,14 @@ function toCodePoint(unicodeSurrogates: string) {
|
|||||||
return r.join("-")
|
return r.join("-")
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmojiMap = {
|
const twemoji = (code: string) =>
|
||||||
codePointToName: Record<string, string>
|
`https://cdnjs.cloudflare.com/ajax/libs/twemoji/15.1.0/svg/${code.toLowerCase()}.svg`
|
||||||
nameToBase64: Record<string, string>
|
const emojiCache: Record<string, Promise<any>> = {}
|
||||||
}
|
|
||||||
|
export function loadEmoji(code: string) {
|
||||||
let emojimap: EmojiMap | undefined = undefined
|
const type = "twemoji"
|
||||||
export async function loadEmoji(code: string) {
|
const key = type + ":" + code
|
||||||
if (!emojimap) {
|
if (key in emojiCache) return emojiCache[key]
|
||||||
const data = await import("./emojimap.json")
|
|
||||||
emojimap = data
|
return (emojiCache[key] = fetch(twemoji(code)).then((r) => r.text()))
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user