@@ -4,17 +4,19 @@ 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 ,
11
11
getPluginNameFromSlug ,
12
+ scoreFilter ,
12
13
scoreMarker ,
13
14
targetScoreIcon ,
14
15
} from './utils.js' ;
15
16
16
17
export function categoriesOverviewSection (
17
18
report : Required < Pick < ScoredReport , 'plugins' | 'categories' > > ,
19
+ options ?: ScoreFilter ,
18
20
) : MarkdownDocument {
19
21
const { categories, plugins } = report ;
20
22
return new MarkdownDocument ( ) . table (
@@ -23,26 +25,29 @@ export function categoriesOverviewSection(
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 ( scoreFilter ( options ) )
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 {
41
46
const { categories, plugins } = report ;
42
-
47
+ const isScoreDisplayed = scoreFilter ( options ) ;
43
48
return new MarkdownDocument ( )
44
49
. heading ( HIERARCHY . level_2 , '🏷 Categories' )
45
- . $foreach ( categories , ( doc , category ) =>
50
+ . $foreach ( categories . filter ( isScoreDisplayed ) , ( doc , category ) =>
46
51
doc
47
52
. heading ( HIERARCHY . level_3 , category . title )
48
53
. paragraph ( metaDescription ( category ) )
@@ -63,13 +68,17 @@ export function categoriesDetailsSection(
63
68
) ,
64
69
) ;
65
70
const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
66
- return categoryGroupItem ( group , groupAudits , pluginTitle ) ;
71
+ return isScoreDisplayed ( group )
72
+ ? categoryGroupItem ( group , groupAudits , pluginTitle )
73
+ : '' ;
67
74
}
68
75
// Add audit details
69
76
else {
70
77
const audit = getSortableAuditByRef ( ref , plugins ) ;
71
78
const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
72
- return categoryRef ( audit , pluginTitle ) ;
79
+ return isScoreDisplayed ( audit )
80
+ ? categoryRef ( audit , pluginTitle )
81
+ : '' ;
73
82
}
74
83
} ) ,
75
84
) ,
0 commit comments