@@ -5,33 +5,31 @@ const devtimeEntries = await getCollection('devtime')
55export const runtimeEntries = await getCollection ( 'runtime' )
66const cwvEntries = await getCollection ( 'cwv' )
77
8- export const cwvStats = cwvEntries
9- . map ( ( entry ) => entry . data )
10- . sort ( ( a , b ) => b . overall . desktop - a . overall . desktop )
11- . map ( ( stat ) => ( {
12- id : stat . id ,
13- framework : stat . framework ,
14- isFocused : true ,
15- lcpDesktopPercent : Math . floor ( stat . lcp . desktop * 100 ) ,
16- lcpMobilePercent : Math . floor ( stat . lcp . mobile * 100 ) ,
17- clsDesktopPercent : Math . floor ( stat . cls . desktop * 100 ) ,
18- clsMobilePercent : Math . floor ( stat . cls . mobile * 100 ) ,
19- fcpDesktopPercent : Math . floor ( stat . fcp . desktop * 100 ) ,
20- fcpMobilePercent : Math . floor ( stat . fcp . mobile * 100 ) ,
21- ttfbDesktopPercent : Math . floor ( stat . ttfb . desktop * 100 ) ,
22- ttfbMobilePercent : Math . floor ( stat . ttfb . mobile * 100 ) ,
23- inpDesktopPercent : Math . floor ( stat . inp . desktop * 100 ) ,
24- inpMobilePercent : Math . floor ( stat . inp . mobile * 100 ) ,
25- } ) )
8+ export type Device = 'desktop' | 'mobile'
9+
10+ export const cwvStats = ( device : Device ) =>
11+ cwvEntries
12+ . map ( ( { data } ) => ( {
13+ id : data . id ,
14+ framework : data . framework ,
15+ isFocused : true ,
16+ overallPercent : Math . floor ( data . overall [ device ] * 100 ) ,
17+ lcpPercent : Math . floor ( data . lcp [ device ] * 100 ) ,
18+ clsPercent : Math . floor ( data . cls [ device ] * 100 ) ,
19+ fcpPercent : Math . floor ( data . fcp [ device ] * 100 ) ,
20+ ttfbPercent : Math . floor ( data . ttfb [ device ] * 100 ) ,
21+ inpPercent : Math . floor ( data . inp [ device ] * 100 ) ,
22+ } ) )
23+ . sort ( ( a , b ) => b . overallPercent - a . overallPercent )
2624
2725export type CWV = 'lcp' | 'cls' | 'fcp' | 'ttfb' | 'inp'
2826
29- export function getCWVDesktopStatsChartData ( cwv : CWV ) {
30- return cwvStats
31- . sort ( ( a , b ) => b [ `${ cwv } DesktopPercent ` ] - a [ `${ cwv } DesktopPercent ` ] )
27+ export function getCWVStatsChartData ( cwv : CWV , device : Device ) {
28+ return cwvStats ( device )
29+ . sort ( ( a , b ) => b [ `${ cwv } Percent ` ] - a [ `${ cwv } Percent ` ] )
3230 . map ( ( stat ) => ( {
3331 name : stat . framework ,
34- value : stat [ `${ cwv } DesktopPercent ` ] ,
32+ value : stat [ `${ cwv } Percent ` ] ,
3533 focused : true ,
3634 } ) )
3735}
0 commit comments