@@ -5,6 +5,14 @@ const fs = require('fs');
55// List to track files with issues
66let filesWithIssues = [ ] ;
77
8+ // Valid doc_type values enum
9+ const VALID_DOC_TYPES = [
10+ 'guide' ,
11+ 'reference' ,
12+ 'changelog' ,
13+ 'landing-page' ,
14+ ] ;
15+
816// Exceptions list configuration
917const EXCEPTIONS_FILE_PATH = path . join ( process . cwd ( ) , 'plugins/frontmatter-validation/frontmatter-exceptions.txt' ) ;
1018let exceptionList = [ ] ;
@@ -140,6 +148,7 @@ async function customParseFrontMatter(params) {
140148 try {
141149 // Use Docusaurus's default parser to get the frontmatter data
142150 const parsedData = await defaultParseFrontMatter ( params ) ;
151+
143152 // Check for required fields
144153 const requiredFields = [ 'title' , 'slug' , 'description' , 'doc_type' ] ;
145154 for ( const field of requiredFields ) {
@@ -148,6 +157,13 @@ async function customParseFrontMatter(params) {
148157 }
149158 }
150159
160+ // Validate doc_type against enum
161+ if ( parsedData . frontMatter . doc_type ) {
162+ if ( ! VALID_DOC_TYPES . includes ( parsedData . frontMatter . doc_type ) ) {
163+ issues . push ( `invalid doc_type '${ parsedData . frontMatter . doc_type } '. Must be one of: ${ VALID_DOC_TYPES . join ( ', ' ) } ` ) ;
164+ }
165+ }
166+
151167 // Check optional fields format
152168 if ( parsedData . frontMatter [ "keywords" ] && ! Array . isArray ( parsedData . frontMatter [ "keywords" ] ) ) {
153169 issues . push ( 'keywords must be a list' ) ;
@@ -376,5 +392,7 @@ module.exports = {
376392 } ,
377393 // Export exception list management functions
378394 reloadExceptions,
379- getExceptions : ( ) => [ ...exceptionList ]
395+ getExceptions : ( ) => [ ...exceptionList ] ,
396+ // Export valid doc types for reference
397+ getValidDocTypes : ( ) => [ ...VALID_DOC_TYPES ]
380398} ;
0 commit comments