Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion plugins/frontmatter-validation/customParseFrontMatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const fs = require('fs');
// List to track files with issues
let filesWithIssues = [];

// Valid doc_type values enum
const VALID_DOC_TYPES = [
'guide',
'reference',
'changelog',
'landing-page',
];

// Exceptions list configuration
const EXCEPTIONS_FILE_PATH = path.join(process.cwd(), 'plugins/frontmatter-validation/frontmatter-exceptions.txt');
let exceptionList = [];
Expand Down Expand Up @@ -140,6 +148,7 @@ async function customParseFrontMatter(params) {
try {
// Use Docusaurus's default parser to get the frontmatter data
const parsedData = await defaultParseFrontMatter(params);

// Check for required fields
const requiredFields = ['title', 'slug', 'description', 'doc_type'];
for (const field of requiredFields) {
Expand All @@ -148,6 +157,13 @@ async function customParseFrontMatter(params) {
}
}

// Validate doc_type against enum
if (parsedData.frontMatter.doc_type) {
if (!VALID_DOC_TYPES.includes(parsedData.frontMatter.doc_type)) {
issues.push(`invalid doc_type '${parsedData.frontMatter.doc_type}'. Must be one of: ${VALID_DOC_TYPES.join(', ')}`);
}
}

// Check optional fields format
if (parsedData.frontMatter["keywords"] && !Array.isArray(parsedData.frontMatter["keywords"])) {
issues.push('keywords must be a list');
Expand Down Expand Up @@ -376,5 +392,7 @@ module.exports = {
},
// Export exception list management functions
reloadExceptions,
getExceptions: () => [...exceptionList]
getExceptions: () => [...exceptionList],
// Export valid doc types for reference
getValidDocTypes: () => [...VALID_DOC_TYPES]
};