fix: added catch for unexpected frontmatter error
This commit is contained in:
committed by
mrugesh mohapatra
parent
b5b6faed30
commit
d4aa7c0b56
@ -1,10 +1,10 @@
|
|||||||
const matter = require('gray-matter');
|
const matter = require('gray-matter');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const dedent = require('dedent');
|
|
||||||
|
|
||||||
const frontmatterCheck = (fullPath, isTranslation, fileContent) => {
|
const frontmatterCheck = (fullPath, isTranslation, fileContent) => {
|
||||||
const { data: frontmatter } = matter(fileContent);
|
|
||||||
let errors = [];
|
let errors = [];
|
||||||
|
try {
|
||||||
|
const { data: frontmatter } = matter(fileContent);
|
||||||
if (!frontmatter || _.isEmpty(frontmatter) || !frontmatter.title) {
|
if (!frontmatter || _.isEmpty(frontmatter) || !frontmatter.title) {
|
||||||
errors.push({
|
errors.push({
|
||||||
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.`,
|
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.`,
|
||||||
@ -17,6 +17,15 @@ const frontmatterCheck = (fullPath, isTranslation, fileContent) => {
|
|||||||
fullPath
|
fullPath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
errors.push({
|
||||||
|
msg: `Unexpected syntax found in the front matter block. Review Travis CI build Details link above for more details.`,
|
||||||
|
fullPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user