2
2
const path = require ( 'path' ) ;
3
3
4
4
// List to track files with issues
5
- const filesWithIssues = [ ] ;
5
+ let filesWithIssues = [ ] ;
6
6
7
7
/**
8
8
* Custom frontmatter parser that enforces specific formatting rules
@@ -254,28 +254,46 @@ async function customParseFrontMatter(params) {
254
254
255
255
// If there are issues, add to the tracking list
256
256
if ( issues . length > 0 ) {
257
- filesWithIssues . push ( {
258
- filePath : relativePath ,
259
- issues
260
- } ) ;
257
+ // Check if we already have an entry for this file path
258
+ const existingIndex = filesWithIssues . findIndex ( item => item . filePath === relativePath ) ;
259
+ if ( existingIndex !== - 1 ) {
260
+ // Update existing entry instead of adding a duplicate
261
+ filesWithIssues [ existingIndex ] . issues = issues ;
262
+ } else {
263
+ // Add new entry
264
+ filesWithIssues . push ( {
265
+ filePath : relativePath ,
266
+ issues
267
+ } ) ;
268
+ }
261
269
}
262
270
263
271
return parsedData ;
264
272
} catch ( error ) {
265
273
console . error ( `Error parsing frontmatter in ${ relativePath } :` , error ) ;
266
- filesWithIssues . push ( {
267
- filePath : relativePath ,
268
- issues : [ `parsing error: ${ error . message } ` ]
269
- } ) ;
274
+
275
+ // Check if we already have an entry for this file path
276
+ const existingIndex = filesWithIssues . findIndex ( item => item . filePath === relativePath ) ;
277
+ if ( existingIndex !== - 1 ) {
278
+ // Update existing entry instead of adding a duplicate
279
+ filesWithIssues [ existingIndex ] . issues = [ `parsing error: ${ error . message } ` ] ;
280
+ } else {
281
+ // Add new entry
282
+ filesWithIssues . push ( {
283
+ filePath : relativePath ,
284
+ issues : [ `parsing error: ${ error . message } ` ]
285
+ } ) ;
286
+ }
287
+
270
288
return await defaultParseFrontMatter ( params ) ;
271
289
}
272
290
}
273
291
274
292
// Export the function and the issue tracker for use in the build plugin
275
293
module . exports = {
276
294
customParseFrontMatter,
277
- getFilesWithIssues : ( ) => filesWithIssues ,
295
+ getFilesWithIssues : ( ) => [ ... filesWithIssues ] , // Return a copy to prevent external modifications
278
296
resetIssues : ( ) => {
279
- filesWithIssues . length = 0 ;
297
+ filesWithIssues = [ ] ; // Replace the array instead of modifying it
280
298
}
281
299
} ;
0 commit comments