@@ -4,7 +4,7 @@ import { slugify } from '../formatting.js';
4
4
import { HIERARCHY } from '../text-formats/index.js' ;
5
5
import { metaDescription } from './formatting.js' ;
6
6
import { getSortableAuditByRef , getSortableGroupByRef } from './sorting.js' ;
7
- import type { ScoredGroup , ScoredReport } from './types.js' ;
7
+ import type { ScoreFilter , ScoredGroup , ScoredReport } from './types.js' ;
8
8
import {
9
9
countCategoryAudits ,
10
10
formatReportScore ,
@@ -15,64 +15,76 @@ import {
15
15
16
16
export function categoriesOverviewSection (
17
17
report : Required < Pick < ScoredReport , 'plugins' | 'categories' > > ,
18
+ options ?: ScoreFilter ,
18
19
) : MarkdownDocument {
20
+ const { isScoreListed = ( _ : number ) => true } = options ?? { } ;
19
21
const { categories, plugins } = report ;
20
22
return new MarkdownDocument ( ) . table (
21
23
[
22
24
{ heading : '🏷 Category' , alignment : 'left' } ,
23
25
{ heading : '⭐ Score' , alignment : 'center' } ,
24
26
{ heading : '🛡 Audits' , alignment : 'center' } ,
25
27
] ,
26
- categories . map ( ( { title, refs, score, isBinary } ) => [
27
- // @TODO refactor `isBinary: boolean` to `targetScore: number` #713
28
- // The heading "ID" is inferred from the heading text in Markdown.
29
- md . link ( `#${ slugify ( title ) } ` , title ) ,
30
- md `${ scoreMarker ( score ) } ${ md . bold (
31
- formatReportScore ( score ) ,
32
- ) } ${ binaryIconSuffix ( score , isBinary ) } `,
33
- countCategoryAudits ( refs , plugins ) . toString ( ) ,
34
- ] ) ,
28
+ categories
29
+ . filter ( ( { score } ) => isScoreListed ( score ) )
30
+ . map ( ( { title, refs, score, isBinary } ) => [
31
+ // @TODO refactor `isBinary: boolean` to `targetScore: number` #713
32
+ // The heading "ID" is inferred from the heading text in Markdown.
33
+ md . link ( `#${ slugify ( title ) } ` , title ) ,
34
+ md `${ scoreMarker ( score ) } ${ md . bold (
35
+ formatReportScore ( score ) ,
36
+ ) } ${ binaryIconSuffix ( score , isBinary ) } `,
37
+ countCategoryAudits ( refs , plugins ) . toString ( ) ,
38
+ ] ) ,
35
39
) ;
36
40
}
37
41
38
42
export function categoriesDetailsSection (
39
43
report : Required < Pick < ScoredReport , 'plugins' | 'categories' > > ,
44
+ options ?: ScoreFilter ,
40
45
) : MarkdownDocument {
46
+ const { isScoreListed = ( _ : number ) => true } = options ?? { } ;
41
47
const { categories, plugins } = report ;
42
48
43
49
return new MarkdownDocument ( )
44
50
. heading ( HIERARCHY . level_2 , '🏷 Categories' )
45
- . $foreach ( categories , ( doc , category ) =>
46
- doc
47
- . heading ( HIERARCHY . level_3 , category . title )
48
- . paragraph ( metaDescription ( category ) )
49
- . paragraph (
50
- md `${ scoreMarker ( category . score ) } Score: ${ md . bold (
51
- formatReportScore ( category . score ) ,
52
- ) } ${ binaryIconSuffix ( category . score , category . isBinary ) } `,
53
- )
54
- . list (
55
- category . refs . map ( ref => {
56
- // Add group details
57
- if ( ref . type === 'group' ) {
58
- const group = getSortableGroupByRef ( ref , plugins ) ;
59
- const groupAudits = group . refs . map ( groupRef =>
60
- getSortableAuditByRef (
61
- { ...groupRef , plugin : group . plugin , type : 'audit' } ,
62
- plugins ,
63
- ) ,
64
- ) ;
65
- const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
66
- return categoryGroupItem ( group , groupAudits , pluginTitle ) ;
67
- }
68
- // Add audit details
69
- else {
70
- const audit = getSortableAuditByRef ( ref , plugins ) ;
71
- const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
72
- return categoryRef ( audit , pluginTitle ) ;
73
- }
74
- } ) ,
75
- ) ,
51
+ . $foreach (
52
+ categories . filter ( ( { score } ) => isScoreListed ( score ) ) ,
53
+ ( doc , category ) =>
54
+ doc
55
+ . heading ( HIERARCHY . level_3 , category . title )
56
+ . paragraph ( metaDescription ( category ) )
57
+ . paragraph (
58
+ md `${ scoreMarker ( category . score ) } Score: ${ md . bold (
59
+ formatReportScore ( category . score ) ,
60
+ ) } ${ binaryIconSuffix ( category . score , category . isBinary ) } `,
61
+ )
62
+ . list (
63
+ category . refs . map ( ref => {
64
+ // Add group details
65
+ if ( ref . type === 'group' ) {
66
+ const group = getSortableGroupByRef ( ref , plugins ) ;
67
+ const groupAudits = group . refs . map ( groupRef =>
68
+ getSortableAuditByRef (
69
+ { ...groupRef , plugin : group . plugin , type : 'audit' } ,
70
+ plugins ,
71
+ ) ,
72
+ ) ;
73
+ const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
74
+ return isScoreListed ( group . score )
75
+ ? categoryGroupItem ( group , groupAudits , pluginTitle )
76
+ : '' ;
77
+ }
78
+ // Add audit details
79
+ else {
80
+ const audit = getSortableAuditByRef ( ref , plugins ) ;
81
+ const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
82
+ return isScoreListed ( audit . score )
83
+ ? categoryRef ( audit , pluginTitle )
84
+ : '' ;
85
+ }
86
+ } ) ,
87
+ ) ,
76
88
) ;
77
89
}
78
90
0 commit comments