@@ -47,6 +47,21 @@ const CURATED_ALLOWED_KEYS = [
4747 'docsUrl'
4848]
4949
50+ const FALLBACK_ICON_CANDIDATES = [
51+ [ 'public' , 'logo.png' ] ,
52+ [ 'public' , 'logo.svg' ] ,
53+ [ 'public' , 'icon.png' ] ,
54+ [ 'public' , 'icon.svg' ] ,
55+ [ 'public' , 'app-icon.png' ] ,
56+ [ 'public' , 'app-icon.svg' ] ,
57+ [ 'src' , 'images' , 'logo.png' ] ,
58+ [ 'src' , 'images' , 'logo.svg' ] ,
59+ [ 'src' , 'images' , 'icon.png' ] ,
60+ [ 'src' , 'images' , 'icon.svg' ] ,
61+ [ 'src' , 'images' , 'extension.png' ] ,
62+ [ 'src' , 'images' , 'extension.svg' ]
63+ ]
64+
5065function readJsonSafe ( filePath ) {
5166 try {
5267 return JSON . parse ( fs . readFileSync ( filePath , 'utf8' ) )
@@ -485,14 +500,40 @@ function resolveManifestIconFile(exampleDirectory, iconPath) {
485500 return null
486501}
487502
503+ function resolveFallbackIconFile ( exampleDirectory , slug ) {
504+ for ( const candidate of FALLBACK_ICON_CANDIDATES ) {
505+ const filePath = path . join ( exampleDirectory , ...candidate )
506+
507+ if ( exists ( filePath ) ) return filePath
508+ }
509+
510+ const slugCandidates = [
511+ path . join ( exampleDirectory , 'public' , `${ slug } .png` ) ,
512+ path . join ( exampleDirectory , 'public' , `${ slug } .svg` ) ,
513+ path . join ( exampleDirectory , 'src' , 'images' , `${ slug } .png` ) ,
514+ path . join ( exampleDirectory , 'src' , 'images' , `${ slug } .svg` )
515+ ]
516+
517+ for ( const filePath of slugCandidates ) {
518+ if ( exists ( filePath ) ) return filePath
519+ }
520+
521+ return null
522+ }
523+
488524function detectTemplateIcon ( exampleDirectory , manifest ) {
489525 const iconPath = pickManifestIconPath ( manifest || { } )
490- if ( ! iconPath ) return null
526+ if ( iconPath ) {
527+ const resolved = resolveManifestIconFile ( exampleDirectory , iconPath )
528+ if ( resolved ) return path . relative ( repoRoot , resolved ) . replace ( / \\ / g, '/' )
529+ }
530+
531+ const slug = path . basename ( exampleDirectory )
532+ const fallback = resolveFallbackIconFile ( exampleDirectory , slug )
491533
492- const resolved = resolveManifestIconFile ( exampleDirectory , iconPath )
493- if ( ! resolved ) return null
534+ if ( ! fallback ) return null
494535
495- return path . relative ( repoRoot , resolved ) . replace ( / \\ / g, '/' )
536+ return path . relative ( repoRoot , fallback ) . replace ( / \\ / g, '/' )
496537}
497538
498539function getGitCommit ( ) {
0 commit comments