Files
freeCodeCamp/validation/guideFolderChecks/frontmatterCheck.js
2018-11-22 02:13:48 +05:30

23 lines
584 B
JavaScript

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: `Missing \`title key\` frontmatter.`,
fullPath
});
}
if (isTranslation && !frontmatter.localeTitle) {
errors.push({
msg: `Missing \`localeTitle key\`frontmatter.`,
fullPath
});
}
return errors;
};
module.exports = { frontmatterCheck };