Files
freeCodeCamp/validation/guide-folder-checks/frontmatter-check.js

24 lines
960 B
JavaScript
Raw Normal View History

2018-11-20 15:31:28 -08:00
const matter = require('gray-matter');
const _ = require('lodash');
2018-11-22 01:19:02 +05:30
const dedent = require('dedent');
2018-11-20 15:31:28 -08:00
const frontmatterCheck = (fullPath, isTranslation, fileContent) => {
const { data: frontmatter } = matter(fileContent);
let errors = [];
if (!frontmatter || _.isEmpty(frontmatter) || !frontmatter.title) {
errors.push({
2018-11-22 01:19:02 +05:30
msg: `Misplaced or missing \`title\` keyword in the front matter block. Review the [style guide](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md#title) for more details.`,
2018-11-20 15:31:28 -08:00
fullPath
});
}
if (isTranslation && !frontmatter.localeTitle) {
errors.push({
2018-11-22 01:19:02 +05:30
msg: `Missing \`localeTitle\` keyword in the front matter block. Review the [style guide](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md#title) for more details.`,
2018-11-20 15:31:28 -08:00
fullPath
});
}
return errors;
};
module.exports = { frontmatterCheck };