File tree Expand file tree Collapse file tree 3 files changed +3209
-9
lines changed Expand file tree Collapse file tree 3 files changed +3209
-9
lines changed Original file line number Diff line number Diff line change @@ -55,8 +55,9 @@ async function generateSocialImage(
55
55
fonts,
56
56
loadAdditionalAsset : async ( languageCode : string , segment : string ) => {
57
57
if ( languageCode === "emoji" ) {
58
- return `data:image/svg+xml;base64, ${ btoa ( await loadEmoji ( getIconCode ( segment ) ) ) } `
58
+ return await loadEmoji ( getIconCode ( segment ) )
59
59
}
60
+
60
61
return languageCode
61
62
} ,
62
63
} )
Original file line number Diff line number Diff line change @@ -25,14 +25,23 @@ function toCodePoint(unicodeSurrogates: string) {
25
25
return r . join ( "-" )
26
26
}
27
27
28
- const twemoji = ( code : string ) =>
29
- `https://cdnjs.cloudflare.com/ajax/libs/twemoji/15.1.0/svg/${ code . toLowerCase ( ) } .svg`
30
- const emojiCache : Record < string , Promise < any > > = { }
28
+ type EmojiMap = {
29
+ codePointToName : Record < string , string >
30
+ nameToBase64 : Record < string , string >
31
+ }
32
+
33
+ let emojimap : EmojiMap | undefined = undefined
34
+ export async function loadEmoji ( code : string ) {
35
+ if ( ! emojimap ) {
36
+ const data = await import ( "./emojimap.json" )
37
+ emojimap = data
38
+ }
39
+
40
+ const name = emojimap . codePointToName [ `U+${ code . toUpperCase ( ) } ` ]
41
+ if ( ! name ) throw new Error ( `codepoint ${ code } not found in map` )
31
42
32
- export function loadEmoji ( code : string ) {
33
- const type = "twemoji"
34
- const key = type + ":" + code
35
- if ( key in emojiCache ) return emojiCache [ key ]
43
+ const b64 = emojimap . nameToBase64 [ name ]
44
+ if ( ! b64 ) throw new Error ( `name ${ name } not found in map` )
36
45
37
- return ( emojiCache [ key ] = fetch ( twemoji ( code ) ) . then ( ( r ) => r . text ( ) ) )
46
+ return b64
38
47
}
You can’t perform that action at this time.
0 commit comments