Skip to content

Commit

Permalink
fix: exception while trying docs validate
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Apr 21, 2020
1 parent ee63716 commit 0e71bf1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Options:
- Title is right-aligned to reveal the common part
- Validation of some columns (status, request time, description length)

### Fields list (19.04.2020):
### Fields list (20.04.2020):
- url
- mixed_content_url
- canonical
Expand All @@ -89,6 +89,7 @@ Options:
- images
- images_without_alt
- images_alt_empty
- images_outer
- links
- links_inner
- links_outer
Expand Down
21 changes: 11 additions & 10 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,6 @@ module.exports = async (baseUrl, options = {}) => {
onSuccess: result => {
if (!result.result) return;

// console validate output
const msgs = [];
const validate = validateResults(result, fields); // TODO: fields declared implicitly
for(let name in validate) {
const res = validate[name];
const msgColor = { warning: color.yellow, error: color.red }[res.type];
msgs.push(`${name}: ${msgColor}${res.msg}${color.reset}`);
}
if(msgs.length > 0) console.log(msgs.join(', '));

if (result.result.error) console.error(`${color.red}Error collect page data: result.result.error${color.reset}`);
// console.log(`html_size: ${result.result.html_size}`);
},
Expand Down Expand Up @@ -273,6 +263,17 @@ module.exports = async (baseUrl, options = {}) => {

result.result.mixed_content_url = mixedContentUrl;

// console validate output
// was in onSuccess(), but causes exception on docs
const msgs = [];
const validate = validateResults(result, fields); // TODO: fields declared implicitly
for(let name in validate) {
const res = validate[name];
const msgColor = { warning: color.yellow, error: color.red }[res.type];
msgs.push(`${name}: ${msgColor}${res.msg}${color.reset}`);
}
if(msgs.length > 0) console.log(msgs.join(', '));

// You can access the page object after requests
result.content = await page.content();
// You need to extend and return the crawled result
Expand Down

0 comments on commit 0e71bf1

Please sign in to comment.