Skip to content

Commit cd1cf6b

Browse files
authored
Merge pull request #4467 from ClickHouse/doc-type-validation
adding doc_type validation
2 parents 1c13e4d + ab238e6 commit cd1cf6b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

plugins/frontmatter-validation/customParseFrontMatter.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ const fs = require('fs');
55
// List to track files with issues
66
let 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
917
const EXCEPTIONS_FILE_PATH = path.join(process.cwd(), 'plugins/frontmatter-validation/frontmatter-exceptions.txt');
1018
let 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

Comments
 (0)