Skip to content

Commit

Permalink
adds support for {# wf_md_include #} (google#4076)
Browse files Browse the repository at this point in the history
  • Loading branch information
petele authored Jan 24, 2017
1 parent 01392a0 commit aab537d
Showing 1 changed file with 45 additions and 23 deletions.
68 changes: 45 additions & 23 deletions gulp-tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,32 @@ function validateMarkdown(filename, commonTags) {
return new Promise(function(resolve, reject) {
readFile(filename)
.then(function(content) {
var isInclude = false;
var errMsg;
var matched;
var errors = 0;
var warnings = 0;

// Check if this is a markdown include file
matched = content.match(/{# wf_md_include #}/gm);
if (matched) {
isInclude = true;
}

// Validate book_path and project_path
if (wfHelper.getRegEx(/^book_path: (.*)\n/m, content, null) === null) {
errMsg = 'Attribute `book_path` missing from top of document';
logError(filename, errMsg)
errors++;
if (isInclude === false) {
errMsg = 'Attribute `book_path` missing from top of document';
logError(filename, errMsg)
errors++;
}
}
if (wfHelper.getRegEx(/^project_path: (.*)\n/m, content, null) === null) {
errMsg = 'Attribute `project_path` missing from top of document';
logError(filename, errMsg)
errors++;
if (isInclude === false) {
errMsg = 'Attribute `project_path` missing from top of document';
logError(filename, errMsg)
errors++;
}
}

// Validate description
Expand All @@ -344,22 +355,24 @@ function validateMarkdown(filename, commonTags) {
}
}



// Validate wf_updated and wf_published
matched = wfHelper.getRegEx(/{# wf_updated_on: (.*?) #}/, content, 'NOT_FOUND');
if (!moment(matched, VALID_DATE_FORMATS, true).isValid()) {
errMsg = 'WF Tag `wf_updated_on` missing or invalid format (YYYY-MM-DD)';
errMsg += ', found: ' + matched;
logError(filename, errMsg)
errors++;
if (isInclude === false) {
if (!moment(matched, VALID_DATE_FORMATS, true).isValid()) {
errMsg = 'WF Tag `wf_updated_on` missing or invalid format (YYYY-MM-DD)';
errMsg += ', found: ' + matched;
logError(filename, errMsg)
errors++;
}
}
matched = wfHelper.getRegEx(/{# wf_published_on: (.*?) #}/, content, 'NOT_FOUND');
if (!moment(matched, VALID_DATE_FORMATS, true).isValid()) {
errMsg = 'WF Tag `wf_published_on` missing or invalid format (YYYY-MM-DD)';
errMsg += ', found: ' + matched;
logError(filename, errMsg)
errors++;
if (isInclude === false) {
if (!moment(matched, VALID_DATE_FORMATS, true).isValid()) {
errMsg = 'WF Tag `wf_published_on` missing or invalid format (YYYY-MM-DD)';
errMsg += ', found: ' + matched;
logError(filename, errMsg)
errors++;
}
}

// Validate featured image path
Expand Down Expand Up @@ -396,7 +409,11 @@ function validateMarkdown(filename, commonTags) {
// Validate page title, and H1's
var numH1 = 0;
matched = content.match(/^# (.*) {: \.page-title[ ]*}/gm);
if (matched) {
if (matched && isInclude === true) {
errMsg = 'Includes cannot contain page titles.';
logError(filename, errMsg)
errors++;
} else if (matched) {
if (matched.length > 1) {
errMsg = 'Page must only have one title tag: ' + matched.join(',');
logError(filename, errMsg)
Expand All @@ -407,7 +424,7 @@ function validateMarkdown(filename, commonTags) {
logError(filename, errMsg)
errors++;
}
} else {
} else if (isInclude === false) {
errMsg = 'Page is missing page title eg: # TITLE {: .page-title }';
logError(filename, errMsg)
errors++;
Expand All @@ -419,10 +436,15 @@ function validateMarkdown(filename, commonTags) {
matched = content.match(/^<h1.*?>/gmi);
if (matched) {
numH1 += matched.length;
}
if (numH1 > 1) {
}
if (isInclude === false && numH1 > 1) {
errMsg = 'Page should only have ONE H1 tag, found ' + numH1;
warnings.push(logWarning(filename, errMsg));
logWarning(filename, errMsg);
warnings++;
} else if (isInclude === true && numH1 >= 1) {
errMsg = 'Includes should not contain any H1 tags, found ' + numH1;
logWarning(filename, errMsg);
warnings++;
}

// Verify authors/translators are in the contributors file
Expand Down

0 comments on commit aab537d

Please sign in to comment.