Skip to content
Open
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
22 changes: 20 additions & 2 deletions 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 @@ -372,5 +388,7 @@ module.exports = {
},
// Export exception list management functions
reloadExceptions,
getExceptions: () => [...exceptionList]
};
getExceptions: () => [...exceptionList],
// Export valid doc types for reference
getValidDocTypes: () => [...VALID_DOC_TYPES]
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am legally obliged to comment newline at end of file, otherwise Dale will hunt me down :P

Loading