@@ -24,6 +24,10 @@ const BACKGROUND = "#ffffff";
2424const FOOTER_BORDER = "#e2e8f0" ;
2525
2626const SITE_HOSTNAME = "simdeck.nativescript.org" ;
27+ const SIMDECK_ICON_URL = new URL (
28+ "../../client/public/simdeck.png" ,
29+ import . meta. url ,
30+ ) ;
2731
2832type SatoriElement = {
2933 type : string ;
@@ -61,6 +65,7 @@ let fontsPromise:
6165 Array < { name : string ; data : Buffer ; weight : 400 | 700 ; style : "normal" } >
6266 >
6367 | undefined ;
68+ let iconDataUrlPromise : Promise < string > | undefined ;
6469
6570async function loadFonts ( ) {
6671 if ( ! fontsPromise ) {
@@ -92,21 +97,30 @@ async function loadFonts() {
9297 return fontsPromise ;
9398}
9499
95- function buildTemplate ( {
96- title,
97- description,
98- category,
99- } : OgPageInfo ) : SatoriElement {
100+ async function loadIconDataUrl ( ) {
101+ if ( ! iconDataUrlPromise ) {
102+ iconDataUrlPromise = fs
103+ . readFile ( SIMDECK_ICON_URL )
104+ . then ( ( icon ) => `data:image/png;base64,${ icon . toString ( "base64" ) } ` ) ;
105+ }
106+ return iconDataUrlPromise ;
107+ }
108+
109+ function buildTemplate (
110+ { title, description, category } : OgPageInfo ,
111+ iconSrc : string ,
112+ ) : SatoriElement {
100113 const topRowChildren : SatoriChildren = [
101114 el ( "div" , { style : { display : "flex" , alignItems : "center" } } , [
102- el ( "div" , {
115+ el ( "img" , {
116+ src : iconSrc ,
117+ alt : "SimDeck icon" ,
103118 style : {
104- width : "44px" ,
105- height : "44px" ,
106- borderRadius : "10px" ,
107- background : `linear-gradient(135deg, ${ BRAND_BLUE } 0%, #4ba3ff 100%)` ,
119+ width : "48px" ,
120+ height : "48px" ,
121+ borderRadius : "12px" ,
108122 marginRight : "18px" ,
109- display : "flex " ,
123+ display : "block " ,
110124 } ,
111125 } ) ,
112126 el (
@@ -244,8 +258,8 @@ function buildTemplate({
244258}
245259
246260export async function renderOgImage ( info : OgPageInfo ) : Promise < Buffer > {
247- const fonts = await loadFonts ( ) ;
248- const svg = await satori ( buildTemplate ( info ) as unknown as never , {
261+ const [ fonts , iconSrc ] = await Promise . all ( [ loadFonts ( ) , loadIconDataUrl ( ) ] ) ;
262+ const svg = await satori ( buildTemplate ( info , iconSrc ) as unknown as never , {
249263 width : WIDTH ,
250264 height : HEIGHT ,
251265 fonts,
0 commit comments