@@ -50,36 +50,47 @@ export function validateHtml(userOptions?: Config) {
5050 } ) ;
5151
5252 return ( site : Lume . Site ) => {
53+ let reports : Report | undefined ;
5354 site . process ( [ ".html" ] , processValidateHtml ) ;
5455
56+ function output ( ) {
57+ if ( ! reports ) {
58+ return ;
59+ }
60+
61+ const { output } = options ;
62+ if ( typeof output === "function" ) {
63+ output ( reports ) ;
64+ } else if ( typeof output === "string" ) {
65+ outputFile ( reports , output ) ;
66+ } else if ( output !== false ) {
67+ outputConsole ( reports ) ;
68+ }
69+ }
70+
71+ site . addEventListener ( "afterUpdate" , output ) ;
72+ site . addEventListener ( "afterBuild" , output ) ;
73+
5574 async function processValidateHtml ( pages : Lume . Page [ ] ) {
56- const reports : Set < Report > = new Set ( ) ;
75+ reports = undefined ;
76+ const pageReports : Set < Report > = new Set ( ) ;
77+
5778 for ( const page of pages ) {
5879 const report = await htmlvalidate . validateString (
5980 page . text ,
6081 page . data . url ,
6182 ) ;
62- reports . add ( report ) ;
83+ pageReports . add ( report ) ;
6384 }
6485
65- const merged = Reporter . merge ( Array . from ( reports . values ( ) ) ) ;
66-
67- // Output
68- const { output } = options ;
69- if ( typeof output === "function" ) {
70- output ( merged ) ;
71- } else if ( typeof output === "string" ) {
72- outputFile ( merged , output ) ;
73- } else if ( output !== false ) {
74- outputConsole ( merged ) ;
75- }
86+ reports = Reporter . merge ( Array . from ( pageReports . values ( ) ) ) ;
7687
7788 const report = site . debugBar ?. collection ( "HTML validator" ) ;
7889 if ( report ) {
7990 report . icon = "file-html" ;
8091 report . empty = "No HTML errors found! 🎉" ;
8192
82- for ( const result of merged . results ) {
93+ for ( const result of reports . results ) {
8394 report . items . push ( {
8495 title : result . filePath ! ,
8596 items : Array . from ( result . messages ) . map ( ( message ) => {
0 commit comments