fix: dont use cdn for twemoji, bake emojis as b64
This commit is contained in:
parent
b397dae951
commit
7ca9dd9a70
3 changed files with 3211 additions and 11 deletions
|
@ -55,8 +55,9 @@ async function generateSocialImage(
|
|||
fonts,
|
||||
loadAdditionalAsset: async (languageCode: string, segment: string) => {
|
||||
if (languageCode === "emoji") {
|
||||
return `data:image/svg+xml;base64,${btoa(await loadEmoji(getIconCode(segment)))}`
|
||||
return await loadEmoji(getIconCode(segment))
|
||||
}
|
||||
|
||||
return languageCode
|
||||
},
|
||||
})
|
||||
|
|
|
@ -25,14 +25,23 @@ function toCodePoint(unicodeSurrogates: string) {
|
|||
return r.join("-")
|
||||
}
|
||||
|
||||
const twemoji = (code: string) =>
|
||||
`https://cdnjs.cloudflare.com/ajax/libs/twemoji/15.1.0/svg/${code.toLowerCase()}.svg`
|
||||
const emojiCache: Record<string, Promise<any>> = {}
|
||||
|
||||
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()))
|
||||
type EmojiMap = {
|
||||
codePointToName: Record<string, string>
|
||||
nameToBase64: Record<string, string>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
3190
quartz/util/emojimap.json
Normal file
3190
quartz/util/emojimap.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue