@@ -2,8 +2,9 @@ import { useMemo } from 'react';
22import { StaticImageData } from 'next/image' ;
33import { compareDesc } from 'date-fns' ;
44import { useData } from 'nextra/hooks' ;
5+ import { fetchPackageInfoCachedAndRetried } from '@/lib/fetch-package-info-cached-and-retried' ;
56import { ALL_TAGS , PLUGINS } from '@/lib/plugins' ;
6- import { cn , fetchPackageInfo , MarketplaceSearch } from '@theguild/components' ;
7+ import { cn , MarketplaceSearch } from '@theguild/components' ;
78
89type Plugin = {
910 title : string ;
@@ -18,43 +19,40 @@ type Plugin = {
1819 className ?: string ;
1920} ;
2021
21- function retry < T > ( fn : ( ) => Promise < T > , retriesLeft = 3 , interval = 1000 ) : Promise < T > {
22- return fn ( ) . catch ( error => {
23- if ( retriesLeft === 1 ) {
24- throw error ;
25- }
26- return new Promise < T > ( resolve => {
27- setTimeout ( ( ) => {
28- resolve ( retry ( fn , retriesLeft - 1 , interval ) ) ;
29- } , interval ) ;
30- } ) ;
31- } ) ;
32- }
33-
3422export const getStaticProps = async ( ) => {
35- const plugins : Plugin [ ] = [ ] ;
36- await Promise . all (
37- PLUGINS . map ( ( { identifier, npmPackage, title, icon, tags, githubReadme, className = '' } ) =>
38- retry ( ( ) => fetchPackageInfo ( npmPackage , githubReadme ) )
39- . then ( ( { readme, createdAt, updatedAt, description, weeklyNPMDownloads = 0 } ) => {
40- plugins . push ( {
41- title,
42- readme,
43- createdAt,
44- updatedAt,
45- description,
46- linkHref : `/plugins/${ identifier } ` ,
47- weeklyNPMDownloads,
48- icon,
49- tags,
50- className,
51- } ) ;
52- } )
53- . catch ( err => {
54- console . warn ( `failed to fetch package info for ${ npmPackage } ` , err ) ;
55- } ) ,
23+ const plugins : Plugin [ ] = await Promise . all (
24+ PLUGINS . map (
25+ async ( { identifier, npmPackage, title, icon, tags, githubReadme, className = '' } ) => {
26+ const {
27+ readme,
28+ createdAt,
29+ updatedAt,
30+ description,
31+ weeklyNPMDownloads = 0 ,
32+ } = await fetchPackageInfoCachedAndRetried ( npmPackage , githubReadme ) ;
33+ const actualReadme = githubReadme ? 'TODO' : readme ;
34+
35+ return {
36+ title,
37+ readme : actualReadme ,
38+ createdAt,
39+ updatedAt,
40+ description,
41+ linkHref : `/plugins/${ identifier } ` ,
42+ weeklyNPMDownloads,
43+ icon,
44+ tags,
45+ className,
46+ } ;
47+ } ,
5648 ) ,
57- ) ;
49+ ) . catch ( err => {
50+ console . error ( 'failed to fetch plugins' , err ) ;
51+ if ( process . env . NODE_ENV === 'development' ) {
52+ return [ ] ; // flakily fails on HMR
53+ }
54+ throw err ;
55+ } ) ;
5856
5957 return {
6058 props : {
0 commit comments