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(
5555 fonts,
5656 loadAdditionalAsset : async ( languageCode : string , segment : string ) => {
5757 if ( languageCode === "emoji" ) {
58- return `data:image/svg+xml;base64, ${ btoa ( await loadEmoji ( getIconCode ( segment ) ) ) } `
58+ return await loadEmoji ( getIconCode ( segment ) )
5959 }
60+
6061 return languageCode
6162 } ,
6263 } )
Original file line number Diff line number Diff line change @@ -25,14 +25,23 @@ function toCodePoint(unicodeSurrogates: string) {
2525 return r . join ( "-" )
2626}
2727
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` )
3142
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` )
3645
37- return ( emojiCache [ key ] = fetch ( twemoji ( code ) ) . then ( ( r ) => r . text ( ) ) )
46+ return b64
3847}
You can’t perform that action at this time.
0 commit comments