@@ -8,7 +8,7 @@ import { JssCompiler } from "@paperbits/styles/jssCompiler";
88import { Logger } from "@paperbits/common/logging/logger" ;
99import { WellKnownEventTypes } from "../../../logging/wellKnownEventTypes" ;
1010
11- export class CustomHtmlPublishViewModelBinder implements ViewModelBinder < CustomHtmlModel , CustomHtmlViewModel > {
11+ export class CustomHtmlPublishViewModelBinder implements ViewModelBinder < CustomHtmlModel , CustomHtmlViewModel > {
1212 constructor (
1313 private readonly styleCompiler : StyleCompiler ,
1414 private readonly blobStorage : IBlobStorage ,
@@ -58,22 +58,31 @@ export class CustomHtmlPublishViewModelBinder implements ViewModelBinder<CustomH
5858 private async getCustomFonts ( ) : Promise < string > {
5959 const globalStyleSheet = await this . styleCompiler . getStyleSheet ( ) ;
6060 const styleSheet = new StyleSheet ( ) ;
61+
6162 if ( globalStyleSheet . fontFaces . length > 0 ) {
6263 for ( let i = 0 ; i < globalStyleSheet . fontFaces . length ; i ++ ) {
6364 const fontFace = globalStyleSheet . fontFaces [ i ] ;
65+
6466 if ( fontFace . source ?. startsWith ( "/fonts/" ) ) {
65- const fontData = await this . blobStorage . downloadBlob ( fontFace . source ) ;
66- this . logger . trackEvent ( WellKnownEventTypes . Publishing , { message : `CustomHtmlPublish: Adding ${ fontFace . source } font as base64` } ) ;
67- const fontDataString = Buffer . from ( fontData ) . toString ( "base64" ) ;
68- fontFace . source = `data:font/truetype;charset=utf-8;base64,${ fontDataString } `
69- styleSheet . fontFaces . push ( fontFace ) ;
67+ try {
68+ const fontData = await this . blobStorage . downloadBlob ( fontFace . source ) ;
69+ this . logger . trackEvent ( WellKnownEventTypes . Publishing , { message : `CustomHtmlPublish: Adding ${ fontFace . source } font as base64` } ) ;
70+ const fontDataString = Buffer . from ( fontData ) . toString ( "base64" ) ;
71+ fontFace . source = `data:font/truetype;charset=utf-8;base64,${ fontDataString } `
72+ styleSheet . fontFaces . push ( fontFace ) ;
73+ }
74+ catch ( error ) {
75+ this . logger . trackError ( error , { message : `Unable to add the font ${ fontFace . source } to Custom HTML widget stylesheet.` } ) ;
76+ }
7077 }
7178 }
7279 }
80+
7381 if ( styleSheet . fontFaces . length > 0 ) {
7482 const compiler = new JssCompiler ( ) ;
7583 return compiler . compile ( styleSheet ) ;
7684 }
85+
7786 return "" ;
7887 }
7988}
0 commit comments