@@ -164,6 +164,52 @@ function makeSafeForCSS(name) {
164164 } ) ;
165165}
166166
167+ export async function scanFonts ( dir , root = dir ) {
168+ const files = fs . readdirSync ( dir ) ;
169+
170+ for ( const file of files ) {
171+ try {
172+ if ( dir && file ) {
173+ // Check if dir and file are not null
174+ const filePath = path . join ( dir , file ) ;
175+ const isDirectory = fs . statSync ( filePath ) . isDirectory ( ) ;
176+ if ( isDirectory ) {
177+ const nmods = process . env . NEXT_PUBLIC_IS_APP_FOLDER
178+ ? "/app/node_modules"
179+ : "node_modules" ;
180+ const slides = process . env . NEXT_PUBLIC_IS_APP_FOLDER
181+ ? "/app/slides"
182+ : "slides" ;
183+ if (
184+ filePath . startsWith ( "." ) ||
185+ filePath . startsWith ( nmods ) ||
186+ filePath . startsWith ( slides )
187+ )
188+ continue ;
189+ scanFonts ( filePath , root ) ;
190+ } else {
191+ // All other files.
192+ const fileName = path . basename ( file ) ;
193+ const relativePath = path . relative ( root , filePath ) ;
194+ const p = relativePath . replace ( / \\ / g, "/" ) ;
195+ if ( p . startsWith ( "main-fonts/" ) ) {
196+ const fontName = path . basename ( file , ".ttf" ) ;
197+ mainFonts [ fontName ] = "assets/" + p ;
198+ mainFontsArray . push ( fontName ) ;
199+ }
200+ if ( p . startsWith ( "nav-fonts/" ) ) {
201+ const fontName = path . basename ( file , ".ttf" ) ;
202+ navFonts [ fontName ] = "assets/" + p ;
203+ navFontsArray . push ( fontName ) ;
204+ }
205+ }
206+ }
207+ } catch ( err ) {
208+ console . error ( `Error reading file while scanning fonts ${ file } ` , err ) ;
209+ }
210+ }
211+ }
212+
167213/**
168214 * If it's the root dir, dirPrefix should be an empty string.
169215 */
0 commit comments