Feat: Ensure markdown formatting (#34547)
<!-- Please follow this checklist and put an x in each of the boxes, like this: [x]. It will ensure that our team takes your pull request seriously. --> - [x] I have read [freeCodeCamp's contribution guidelines](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/CONTRIBUTING.md). - [x] My pull request has a descriptive title (not a vague title like `Update index.md`) - [x] My pull request targets the `master` branch of freeCodeCamp. Closes #34535
This commit is contained in:
committed by
mrugesh mohapatra
parent
6685494344
commit
2d3c2efa2a
34
tools/scripts/ci/ensure-guide-formatting.js
Normal file
34
tools/scripts/ci/ensure-guide-formatting.js
Normal file
@ -0,0 +1,34 @@
|
||||
const readdirp = require('readdirp-walk');
|
||||
const { has } = require('lodash');
|
||||
const ora = require('ora');
|
||||
|
||||
const {
|
||||
guideRoot,
|
||||
checkGuideFile,
|
||||
checkFrontmatter,
|
||||
extractLangFromFileName
|
||||
} = require('./md-testing-utils');
|
||||
|
||||
const spinner = ora('Checking guide markdown formatting').start();
|
||||
|
||||
const guideFrontmatterValidator = file => frontmatter => {
|
||||
const hasLocale =
|
||||
extractLangFromFileName(file) === 'english'
|
||||
? true
|
||||
: has(frontmatter, 'localeTitle');
|
||||
const hasTitle = has(frontmatter, 'title');
|
||||
return hasLocale && hasTitle;
|
||||
};
|
||||
|
||||
readdirp({ root: guideRoot })
|
||||
.on('data', file =>
|
||||
Promise.all([
|
||||
checkGuideFile(file),
|
||||
checkFrontmatter(file, { validator: guideFrontmatterValidator(file) })
|
||||
]).catch(err => {
|
||||
console.error(err);
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
})
|
||||
)
|
||||
.on('end', () => spinner.stop());
|
Reference in New Issue
Block a user