@@ -6,7 +6,7 @@ const { getFilesWithIssues, resetIssues } = require('./customParseFrontMatter');
66 * Custom plugin to enforce frontmatter formatting rules
77 * and fail the build if any issues are found
88 */
9- function frontmatterValidatorPlugin ( ) {
9+ function frontmatterValidatorPlugin ( context , options ) {
1010 return {
1111 name : 'frontmatter-validator-plugin' ,
1212
@@ -20,30 +20,35 @@ function frontmatterValidatorPlugin() {
2020 const filesWithIssues = getFilesWithIssues ( ) ;
2121
2222 if ( filesWithIssues . length > 0 ) {
23- console . error ( '\n🚨 Build failed: Frontmatter validation issues found' ) ;
24- console . error ( 'The following files have frontmatter issues:' ) ;
25-
26- filesWithIssues . forEach ( ( { filePath, issues } ) => {
27- console . error ( `\n📄 ${ filePath } :` ) ;
28- issues . forEach ( issue => {
29- console . error ( ` • ${ issue } ` ) ;
23+ if ( options && options . failBuild ) {
24+ console . error ( '\n🚨 Build failed: Frontmatter validation issues found' ) ;
25+ console . error ( 'The following files have frontmatter issues:' ) ;
26+
27+ filesWithIssues . forEach ( ( { filePath, issues } ) => {
28+ console . error ( `\n📄 ${ filePath } :` ) ;
29+ issues . forEach ( issue => {
30+ console . error ( ` • ${ issue } ` ) ;
31+ } ) ;
3032 } ) ;
31- } ) ;
32-
33- // Write the results to a log file for easier review
34- const logContent = filesWithIssues
35- . map ( ( { filePath, issues } ) =>
36- `${ filePath } :\n${ issues . map ( issue => ` • ${ issue } ` ) . join ( '\n' ) } ` )
37- . join ( '\n\n' ) ;
38-
39- fs . writeFileSync (
40- path . join ( process . cwd ( ) , 'frontmatter-validation-errors.log' ) ,
41- logContent
42- ) ;
43- console . log ( 'See frontmatter-validation-errors.log (when running locally)' )
44-
45- // Fail the build by throwing an error
46- throw new Error ( 'Frontmatter validation failed. See frontmatter-validation-errors.log for details.' ) ;
33+
34+ // Write the results to a log file for easier review
35+ const logContent = filesWithIssues
36+ . map ( ( { filePath, issues } ) =>
37+ `${ filePath } :\n${ issues . map ( issue => ` • ${ issue } ` ) . join ( '\n' ) } ` )
38+ . join ( '\n\n' ) ;
39+
40+ fs . writeFileSync (
41+ path . join ( process . cwd ( ) , 'frontmatter-validation-errors.log' ) ,
42+ logContent
43+ ) ;
44+ console . log ( 'See frontmatter-validation-errors.log (when running locally)' )
45+
46+ // Fail the build by throwing an error
47+ throw new Error ( '🚨Frontmatter validation failed. See frontmatter-validation-errors.log for details.' ) ;
48+ } else {
49+ console . log ( `⚠️ Warning: Found ${ filesWithIssues . length } files containing problems with frontmatter` )
50+ }
51+
4752 } else {
4853 console . log ( '✅ All markdown files passed frontmatter validation.' ) ;
4954 }
0 commit comments