Files
freeCodeCamp/validation/guideFolderChecks/frontmatterCheck.js

23 lines
609 B
JavaScript
Raw Normal View History

2018-11-20 15:31:28 -08:00
const matter = require('gray-matter');
const _ = require('lodash');
const frontmatterCheck = (fullPath, isTranslation, fileContent) => {
const { data: frontmatter } = matter(fileContent);
let errors = [];
if (!frontmatter || _.isEmpty(frontmatter) || !frontmatter.title) {
errors.push({
msg: `Misplaced frontmatter or missing \`title key\` frontmatter.`,
2018-11-20 15:31:28 -08:00
fullPath
});
}
if (isTranslation && !frontmatter.localeTitle) {
errors.push({
msg: `Missing \`localeTitle key\`frontmatter.`,
fullPath
});
}
return errors;
};
module.exports = { frontmatterCheck };