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({
|
2018-11-20 18:34:48 -08:00
|
|
|
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 };
|