@@ -4,17 +4,19 @@ import { slugify } from '../formatting.js';
44import { HIERARCHY } from '../text-formats/index.js' ;
55import { metaDescription } from './formatting.js' ;
66import { getSortableAuditByRef , getSortableGroupByRef } from './sorting.js' ;
7- import type { ScoredGroup , ScoredReport } from './types.js' ;
7+ import type { ScoreFilter , ScoredGroup , ScoredReport } from './types.js' ;
88import {
99 countCategoryAudits ,
1010 formatReportScore ,
1111 getPluginNameFromSlug ,
12+ scoreFilter ,
1213 scoreMarker ,
1314 targetScoreIcon ,
1415} from './utils.js' ;
1516
1617export function categoriesOverviewSection (
1718 report : Required < Pick < ScoredReport , 'plugins' | 'categories' > > ,
19+ options ?: ScoreFilter ,
1820) : MarkdownDocument {
1921 const { categories, plugins } = report ;
2022 return new MarkdownDocument ( ) . table (
@@ -23,26 +25,29 @@ export function categoriesOverviewSection(
2325 { heading : '⭐ Score' , alignment : 'center' } ,
2426 { heading : '🛡 Audits' , alignment : 'center' } ,
2527 ] ,
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+ ] ) ,
3539 ) ;
3640}
3741
3842export function categoriesDetailsSection (
3943 report : Required < Pick < ScoredReport , 'plugins' | 'categories' > > ,
44+ options ?: ScoreFilter ,
4045) : MarkdownDocument {
4146 const { categories, plugins } = report ;
42-
47+ const isScoreDisplayed = scoreFilter ( options ) ;
4348 return new MarkdownDocument ( )
4449 . heading ( HIERARCHY . level_2 , '🏷 Categories' )
45- . $foreach ( categories , ( doc , category ) =>
50+ . $foreach ( categories . filter ( isScoreDisplayed ) , ( doc , category ) =>
4651 doc
4752 . heading ( HIERARCHY . level_3 , category . title )
4853 . paragraph ( metaDescription ( category ) )
@@ -63,13 +68,17 @@ export function categoriesDetailsSection(
6368 ) ,
6469 ) ;
6570 const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
66- return categoryGroupItem ( group , groupAudits , pluginTitle ) ;
71+ return isScoreDisplayed ( group )
72+ ? categoryGroupItem ( group , groupAudits , pluginTitle )
73+ : '' ;
6774 }
6875 // Add audit details
6976 else {
7077 const audit = getSortableAuditByRef ( ref , plugins ) ;
7178 const pluginTitle = getPluginNameFromSlug ( ref . plugin , plugins ) ;
72- return categoryRef ( audit , pluginTitle ) ;
79+ return isScoreDisplayed ( audit )
80+ ? categoryRef ( audit , pluginTitle )
81+ : '' ;
7382 }
7483 } ) ,
7584 ) ,
0 commit comments