Skip to content

Commit

Permalink
Validate heading names
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed Apr 15, 2018
1 parent 85bf8d3 commit 207778b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions bin/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ const contentPath = (
);


/**
* Define the heading names expected in company profiles.
*/
const headingsRequired = [
'Company blurb',
];
const headingsOptional = [
'Company size',
'Remote status',
'Region',
'Company technologies',
'Office locations',
'How to apply',
];


/**
* Build list of Markdown files containing company profiles.
*/
Expand Down Expand Up @@ -181,6 +197,34 @@ profileFilenames.forEach( filename => {
) {
error( 'No link to company profile from readme' );
}

// Build list of headings contained in this Markdown profile.

const profileHeadings = [];

$( 'h2' ).each( ( i, el ) => {
const headingName = $( el ).html();
profileHeadings.push( headingName );
if (
headingsRequired.indexOf( headingName ) === -1 &&
headingsOptional.indexOf( headingName ) === -1
) {
error(
'Invalid heading name: "%s". Expected one of: %s',
headingName,
JSON.stringify( headingsRequired.concat( headingsOptional ) )
);
}
} );

headingsRequired.forEach( headingName => {
if ( profileHeadings.indexOf( headingName ) === -1 ) {
error(
'Required heading "%s" not found.',
headingName
);
}
} );
} );

console.log();
Expand Down

0 comments on commit 207778b

Please sign in to comment.