@@ -6,7 +6,7 @@ const { getFilesWithIssues, resetIssues } = require('./customParseFrontMatter');
6
6
* Custom plugin to enforce frontmatter formatting rules
7
7
* and fail the build if any issues are found
8
8
*/
9
- function frontmatterValidatorPlugin ( ) {
9
+ function frontmatterValidatorPlugin ( context , options ) {
10
10
return {
11
11
name : 'frontmatter-validator-plugin' ,
12
12
@@ -20,30 +20,35 @@ function frontmatterValidatorPlugin() {
20
20
const filesWithIssues = getFilesWithIssues ( ) ;
21
21
22
22
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
+ } ) ;
30
32
} ) ;
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
+
47
52
} else {
48
53
console . log ( '✅ All markdown files passed frontmatter validation.' ) ;
49
54
}
0 commit comments