diff --git a/ampbench_handlers.js b/ampbench_handlers.js
index dbe71fa..eb63643 100644
--- a/ampbench_handlers.js
+++ b/ampbench_handlers.js
@@ -38,6 +38,7 @@ function validator_signature() {
// app validation check status constants
//
+/* eslint-disable no-multi-spaces */
const
CHECK_FAIL = 'FAIL',
CHECK_PASS = 'PASS',
@@ -45,14 +46,14 @@ const
CHECK_WARN = 'WARNING',
CHECK_NONE = 'UNKNOWN';
const // http://www.tutorialspoint.com/html/html_colors.htm
- CHECK_FAIL_CSS = '' + CHECK_FAIL + '',
- CHECK_PASS_CSS = '' + CHECK_PASS + '',
- CHECK_INFO_CSS = '' + CHECK_INFO + '',
- CHECK_WARN_CSS = '' + CHECK_WARN + '',
- CHECK_NONE_CSS = '' + CHECK_NONE + '';
+ CHECK_FAIL_CSS = '' + CHECK_FAIL + '',
+ CHECK_PASS_CSS = '' + CHECK_PASS + '',
+ CHECK_INFO_CSS = '' + CHECK_INFO + '',
+ CHECK_WARN_CSS = '' + CHECK_WARN + '',
+ CHECK_NONE_CSS = '' + CHECK_NONE + '';
const
get_check_status_css = (status) => {
- switch(status) {
+ switch (status) {
case CHECK_FAIL: return CHECK_FAIL_CSS;
case CHECK_PASS: return CHECK_PASS_CSS;
case CHECK_INFO: return CHECK_INFO_CSS;
@@ -60,6 +61,7 @@ const
default: return CHECK_NONE_CSS;
}
};
+/* eslint-enable no-multi-spaces */
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// app imports, main instance and view templates
@@ -67,7 +69,7 @@ const
const os = require('os');
const fs = require('fs');
-const path = require("path");
+const path = require('path');
const http = require('http');
const https = require('https');
const url = require('url');
@@ -129,7 +131,7 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
canonical_parsed_return.result = ''; // make a result field
let canonical_url_found = canonical_parsed_return.canonical_url,
- amphtml_url_found = canonical_parsed_return.amphtml_urls, // could be multiples
+ amphtml_url_found = canonical_parsed_return.amphtml_urls, // could be multiples
fetch_duration_amp = http_response.duration_in_milliseconds,
fetch_duration_canonical = http_response_canonical.duration_in_milliseconds,
fetch_duration_amp_cache = 0, fetch_status_amp_cache = '';
@@ -139,10 +141,10 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
canonical_parsed_return.result += '[Canonical URL is reachable]';
if ('' !== canonical_url_found) {
canonical_parsed_return.canonical_url = benchlib.make_url_href(
- canonical_url_found, canonical_url_found);
+ canonical_url_found, canonical_url_found);
}
if (0 < amphtml_url_found.length) {
- canonical_parsed_return.result += '[AMP link found in Canonical page]';
+ canonical_parsed_return.result += '[AMP link found in Canonical page]';
if (!amphtml_url_found.includes(url_to_validate)) { // amp link not pointing back!!!
// if (!amphtml_url_found.includes(url_to_validate) &&
// !amphtml_url_found.includes(url_to_validate.slice(0,-1)) &&
@@ -150,15 +152,15 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
// !amphtml_url_found.includes(url_to_validate.trimEnd())) { // amp link not pointing back!!!
canonical_parsed_return.status = CHECK_FAIL;
canonical_parsed_return.result += '[FAIL: AMP link in Canonical page does not refer to the current AMP page]';
- } else if(amphtml_url_found.length > 1) {
- canonical_parsed_return.status = CHECK_WARN;
+ } else if (amphtml_url_found.length > 1) {
+ canonical_parsed_return.status = CHECK_WARN;
canonical_parsed_return.result += '[WARNING: Multiple AMP links found in Canonical page]';
- } else {
+ } else {
canonical_parsed_return.status = CHECK_PASS;
canonical_parsed_return.result += '[AMP link in Canonical page refers to the current AMP page]';
}
canonical_parsed_return.amphtml_url = benchlib.make_url_href(
- amphtml_url_found[0], amphtml_url_found[0]); // could be multiples, if so take the 1st one
+ amphtml_url_found[0], amphtml_url_found[0]); // could be multiples, if so take the 1st one
canonical_parsed_return.amphtml_urls = benchlib.make_url_href_list(canonical_parsed_return.amphtml_urls);
} else {
canonical_parsed_return.status = CHECK_WARN;
@@ -186,7 +188,7 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
canonical_parsed_return.status = get_check_status_css(canonical_parsed_return.status);
canonical_parsed_return.url = benchlib.make_url_href(
- canonical_parsed_return.url, canonical_parsed_return.url);
+ canonical_parsed_return.url, canonical_parsed_return.url);
const on_check_robots_txt = (check_robots_txt_return) => {
@@ -194,7 +196,7 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
fetch_duration_amp_cache = check_google_amp_cache_return.duration_in_milliseconds;
fetch_status_amp_cache = 0 < fetch_duration_amp_cache ? '' :
- '[' + check_google_amp_cache_return.check_google_amp_cache_results + ']';
+ '[' + check_google_amp_cache_return.check_google_amp_cache_results + ']';
const on_check_url_metadata = (metadata_return) => {
@@ -203,13 +205,13 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
article_image_url = metadata_return.article_image.url;
const on_check_image_urls_are_reachable = (publisher_logo_url_reachable_ret,
- article_image_url_reachable_ret) => {
+ article_image_url_reachable_ret) => {
let amp_url_href = benchlib.make_url_href(url_to_validate, url_to_validate),
amphtml_url_href = '',
// amphtml_url_href = benchlib.make_url_href(amphtml_url, amphtml_url),
canonical_url_href = benchlib.make_url_href(
- parse_amplinks.canonical_url,
- parse_amplinks.canonical_url);
+ parse_amplinks.canonical_url,
+ parse_amplinks.canonical_url);
let url_to_validate_enc = encodeURIComponent(url_to_validate),
redirect_url = '';
@@ -219,14 +221,14 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
// - - - -
if (( // a Canonical?
- url_to_validate === parse_amplinks.canonical_url &&
+ url_to_validate === parse_amplinks.canonical_url &&
'' !== parse_amplinks.amphtml_url &&
parse_amplinks.amphtml_url !== url_to_validate
- ) || (
- '' === parse_amplinks.canonical_url &&
+ ) || (
+ '' === parse_amplinks.canonical_url &&
'' !== parse_amplinks.amphtml_url &&
parse_amplinks.amphtml_url !== url_to_validate
- )) {
+ )) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// CASE 1:
// - - - -
@@ -280,7 +282,7 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
if (parse_amplinks.amphtml_url !== url_to_validate) { // *and* the amphtml_link rel link is not the validated URL
check_amp_links_amphtml_results += '[the AMPHTML link also does not point at the current page]';
}
- if (parse_amplinks.canonical_url === url_to_validate) { // these should *not* be identical here except for standalone!
+ if (parse_amplinks.canonical_url === url_to_validate) { // these should *not* be identical here except for standalone!
check_amp_links_canonical_results += '[Canonical equal to AMP: standalone AMP page?]';
}
}
@@ -413,7 +415,7 @@ function validate(route, user_agent, user_agent_name, req, res, on_validate_call
user_agent_name: benchlib.get_global_user_agent_name(),
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
response_timestamp: new Date().toISOString(), // The timezone is always zero UTC offset, as per suffix "Z"
- amphtml_validator_signature: validator_signature().substr(0, 21+16) + ']', // only show left 16 chars
+ amphtml_validator_signature: validator_signature().substr(0, 21 + 16) + ']', // only show left 16 chars
http_response: http_response,
http_response_code: http_response.http_response_code,
http_response_statusIsOK: http_response.statusIsOK(),
diff --git a/ampbench_lib.js b/ampbench_lib.js
index 1261a40..efff765 100644
--- a/ampbench_lib.js
+++ b/ampbench_lib.js
@@ -36,7 +36,7 @@ const valid_url = require('valid-url');
const wget = require('wget-improved');
const robots_parser = require('robots-parser');
const util = require('util');
-const inspect_obj = (obj) => {return util.inspect(obj, { showHidden: true, depth: null })};
+const inspect_obj = (obj) => {return util.inspect(obj, { showHidden: true, depth: null });};
const cheerio = require('cheerio');
const S = require('string');
const hasBom = require('has-bom');
@@ -194,26 +194,26 @@ class HttpResponse {
return (1 < this.redirects_count);
}
print() {
- puts('=> url : ' + this.url);
- puts('=> url_error : ' + this.url_error);
- puts('=> is_https : ' + this.is_https);
- puts('=> http_response_code : ' + this.http_response_code);
- puts('=> http_response_text : ' + this.http_response_text);
- puts('=> duration_in_milliseconds : ' + this.duration_in_milliseconds);
- puts('=> wasRedirected : ' + this.wasRedirected());
- puts('=> redirects_count : ' + this.redirects_count);
- puts('=> redirects_urls :\n' + this.redirects_urls.join('\n'));
+ puts('=> url : ' + this.url);
+ puts('=> url_error : ' + this.url_error);
+ puts('=> is_https : ' + this.is_https);
+ puts('=> http_response_code : ' + this.http_response_code);
+ puts('=> http_response_text : ' + this.http_response_text);
+ puts('=> duration_in_milliseconds : ' + this.duration_in_milliseconds);
+ puts('=> wasRedirected : ' + this.wasRedirected());
+ puts('=> redirects_count : ' + this.redirects_count);
+ puts('=> redirects_urls :\n' + this.redirects_urls.join('\n'));
// puts('=> redirects_urls (inspect) : ' + util.inspect(this.redirects_urls));
- puts('=> is_https_cert_authorized : ' + this.is_https_cert_authorized);
- puts('=> is_https_cert_ssl_error : ' + this.is_https_cert_ssl_error);
+ puts('=> is_https_cert_authorized : ' + this.is_https_cert_authorized);
+ puts('=> is_https_cert_ssl_error : ' + this.is_https_cert_ssl_error);
}
printWithBody() {
this.print();
- puts('=> http_response_body :\n' + this.http_response_body);
+ puts('=> http_response_body :\n' + this.http_response_body);
}
printWithCert() {
this.print();
- puts('=> is_https_cert_certificate:\n' + util.inspect(this.is_https_cert_certificate));
+ puts('=> is_https_cert_certificate:\n' + util.inspect(this.is_https_cert_certificate));
}
printWithResponse() {
this.print();
@@ -363,7 +363,7 @@ class HttpBodySniffer {
json_ld: '' !== this._json_ld_script,
json_ld_schema_org:
this.bodyContains('"@context"') && (
- this.bodyContains('"http://schema.org/"') ||
+ this.bodyContains('"http://schema.org/"') ||
this.bodyContains('"https://schema.org/"') ),
jsonld_type: {
Article:
@@ -591,7 +591,7 @@ class HttpBodySniffer {
if (this.isValidForUse) {
return this._contains;
} else {
- throw 'ERROR: HttpBodySniffer is not valid for use';
+ throw 'ERROR: HttpBodySniffer is not valid for use'; // eslint-disable-line no-throw-literal
}
}
get containsAmpHtmlSignature() {
@@ -629,7 +629,7 @@ class HttpBodySniffer {
return this._amphtml_href2.substr(0, 256).trim();
} else if (this._contains.amphtml_link) {
return this._amphtml_href.substr(0, 256).trim();
- } else return '';
+ } else {return '';}
}
return '';
}
@@ -644,7 +644,7 @@ class HttpBodySniffer {
return this._canonical_href2.substr(0, 256).trim();
} else if (this._contains.canonical_link) {
return this._canonical_href.substr(0, 256).trim();
- } else return '';
+ } else {return '';}
}
return '';
}
@@ -680,8 +680,8 @@ class HttpBodySniffer {
}
get containsMixedStructuredDataMarkup() {
let _ret = {
- status: false,
- result: ''
+ status: false,
+ result: ''
};
if (this.isValidForUse) {
_ret.status = this.containsJsonLd && this.containsMicroData;
@@ -775,7 +775,7 @@ class HttpBodyParser extends HttpBodySniffer {
this._index_of_search = this._body.indexOf(search_text);
return (-1 < this._index_of_search);
} else {
- throw 'ERROR: HttpBodyParser instance is not valid for use';
+ throw 'ERROR: HttpBodyParser instance is not valid for use'; // eslint-disable-line no-throw-literal
}
}
}
@@ -788,18 +788,18 @@ class HttpBodyParser extends HttpBodySniffer {
// Latest AMP cached validator from: 'https://cdn.ampproject.org/v0/validator.js'
// https://github.com/ampproject/amphtml/blob/master/validator/nodejs/index.js
// https://github.com/ampproject/amphtml/blob/master/validator/nodejs/index.js#L286
-const VALIDATOR_JS_URL = 'https://cdn.ampproject.org/v0/validator.js';
+const VALIDATOR_JS_URL = 'https://cdn.ampproject.org/v0/validator.js';
const VALIDATOR_JS_FILE = './validator/validator.js';
const amphtml_validator = require('amphtml-validator');
-var amphtml_validator_instance = null; // cache the instance
+var amphtml_validator_instance = null; // cache the instance
// The signature for the validator.js file that this module is currently using.
// This gets updated in sync with amphtml_validator_instance.
-var amphtml_validator_signature = '*unavailable*';
+var amphtml_validator_signature = '*unavailable*';
function lib_amphtml_validator_signature() {
- return amphtml_validator_signature;
+ return amphtml_validator_signature;
}
// Computes a SHA256 signature, which is what you'd get if you were to
@@ -811,11 +811,11 @@ function lib_extract_validator_signature(validator_js_contents) {
function lib_fetch_cdn_validator_signature(callback) {
fetch(VALIDATOR_JS_URL)
- .then(function(res) {
- return res.text();
- }).then(function(validator_js_contents) {
- callback(lib_extract_validator_signature(validator_js_contents));
- });
+ .then(function(res) {
+ return res.text();
+ }).then(function(validator_js_contents) {
+ callback(lib_extract_validator_signature(validator_js_contents));
+ });
}
/**
@@ -829,9 +829,9 @@ function lib_load_validator(opt_force_reload) {
}
// amphtml_validator_instance is a module level global, so we cache it and will
// return it unless opt_force_reload is true.
- const validator_js_contents = fs.readFileSync(VALIDATOR_JS_FILE).toString()
+ const validator_js_contents = fs.readFileSync(VALIDATOR_JS_FILE).toString();
amphtml_validator_signature = lib_extract_validator_signature(
- validator_js_contents);
+ validator_js_contents);
amphtml_validator_instance = amphtml_validator.newInstance(validator_js_contents);
return amphtml_validator_instance;
}
@@ -841,7 +841,7 @@ function lib_load_validator(opt_force_reload) {
*/
function lib_download_validator(callback_on_complete) {
const _callback_on_complete = callback_on_complete || null;
- const source_url = VALIDATOR_JS_URL;
+ const source_url = VALIDATOR_JS_URL;
const target_file = VALIDATOR_JS_FILE;
var options = {
// see: https://www.npmjs.com/package/wget-improved#download-and-request-method-options
@@ -855,7 +855,7 @@ function lib_download_validator(callback_on_complete) {
});
download.on('end', function(output) {
console.log('[VALIDATOR REFRESH] END: ' + output);
- lib_load_validator(true); // reload the validator into memory
+ lib_load_validator(true); // reload the validator into memory
if (null != _callback_on_complete) {
_callback_on_complete(amphtml_validator_signature);
}
@@ -893,7 +893,7 @@ function lib_renderValidationResult(validationResult, validate_url) {
}
for (let ii = 0; ii < validationResult.errors.length; ii++) {
const error = validationResult.errors[ii];
- let msg = validate_url + ': ' + 'line ' + error.line + ', col ' + error.col + ': ' + error.message;
+ let msg = validate_url + ': line ' + error.line + ', col ' + error.col + ': ' + error.message;
if (error.specUrl) {
msg += ' (see ' + error.specUrl + ')';
}
@@ -934,7 +934,7 @@ function fetch_and_validate_url(validate_url, on_output_callback, as_json) {
url_parsed_path = url_parsed.pathname;
if (url_parsed.search) {
- url_parsed_path = url_parsed.pathname + url_parsed.search
+ url_parsed_path = url_parsed.pathname + url_parsed.search;
}
const callback = (res) => {
@@ -968,7 +968,7 @@ function fetch_and_validate_url(validate_url, on_output_callback, as_json) {
const http_options = {
host: url_parsed.hostname,
path: url_parsed_path,
- headers: {'User-Agent': UA_AMPBENCH}
+ headers: { 'User-Agent': UA_AMPBENCH }
};
let req = http_response.http_client.request(http_options, callback);
req.on('error', (err) => {
@@ -1005,7 +1005,7 @@ function fetch_and_parse_url_for_amplinks(request_url, on_parsed_callback) {
url_parsed_path = url_parsed.pathname;
if (url_parsed.search) {
- url_parsed_path = url_parsed.pathname + url_parsed.search
+ url_parsed_path = url_parsed.pathname + url_parsed.search;
}
if (full_path.indexOf('http://') === 0 ||
@@ -1036,10 +1036,10 @@ function fetch_and_parse_url_for_amplinks(request_url, on_parsed_callback) {
http_response.http_response_body = body;
__temp = parse_body_for_amplinks(body, http_response);
__return.url = full_path;
- __return.canonical_url = __temp.canonical_url;
- __return.amphtml_url = __temp.amphtml_url;
- __return.amphtml_urls = __temp.amphtml_urls;
- __return.has_dns_prefetch = __temp.has_dns_prefetch;
+ __return.canonical_url = __temp.canonical_url;
+ __return.amphtml_url = __temp.amphtml_url;
+ __return.amphtml_urls = __temp.amphtml_urls;
+ __return.has_dns_prefetch = __temp.has_dns_prefetch;
__return.status = __temp.amphtml_urls.length > 0 ? CHECK_WARN : CHECK_PASS;
on_parsed_callback(http_response, __return); // !!! RETURN to front-end - - - - - - - - - - - - - - -
@@ -1049,7 +1049,7 @@ function fetch_and_parse_url_for_amplinks(request_url, on_parsed_callback) {
const http_options = {
host: url_parsed.hostname,
path: url_parsed_path,
- headers: {'User-Agent': UA_AMPBENCH}
+ headers: { 'User-Agent': UA_AMPBENCH }
};
let req = http_response.http_client.request(http_options, callback);
req.on('error', (err) => {
@@ -1079,8 +1079,8 @@ function fetch_and_parse_url_for_amplinks(request_url, on_parsed_callback) {
function get_http_redirect_status(http_response) {
let
__ret = 2 < http_response.redirects_count ? CHECK_INFO : CHECK_PASS;
- __ret = 3 < http_response.redirects_count ? CHECK_WARN : __ret;
- __ret = 5 < http_response.redirects_count ? CHECK_FAIL : __ret;
+ __ret = 3 < http_response.redirects_count ? CHECK_WARN : __ret;
+ __ret = 5 < http_response.redirects_count ? CHECK_FAIL : __ret;
return __ret;
}
@@ -1101,7 +1101,7 @@ function build_warning_lines_from_validation_output(url, output, filter) {
FILTER_SIZE_SHORT = '/spec.html#maximum-size',
FILTER_SIZE = '' === filter.trim() ? FILTER_SIZE_SHORT : filter;
- let amp_val_results_len = output.length,
+ let amp_val_results_len = output.length,
amp_val_results = 0 < amp_val_results_len ? output.split(os.EOL) : ''; // payload packaged as output.join(os.EOL);
let amp_val_warnings_len = amp_val_results_len - 1,
@@ -1219,41 +1219,41 @@ function check_url_is_reachable_with_user_agent(fetch_url, user_agent, callback)
try {
fetch(fetch_url, options)
- .then(function(res) {
+ .then(function(res) {
// _log_response(res);
- _ret.http_response_code = res.status;
- if (res.status === 200) {
- _ret.ok = true;
- _ret.status = CHECK_PASS;
- _ret.result = '[HTTP: ' + res.status + '] URL is reachable';
- _ret.size = res.size;
- _ret.err = false; // make it false rather than null
- } else {
+ _ret.http_response_code = res.status;
+ if (res.status === 200) {
+ _ret.ok = true;
+ _ret.status = CHECK_PASS;
+ _ret.result = '[HTTP: ' + res.status + '] URL is reachable';
+ _ret.size = res.size;
+ _ret.err = false; // make it false rather than null
+ } else {
+ _ret.ok = false;
+ _ret.status = CHECK_FAIL;
+ _ret.result = '[HTTP: ' + res.status + ': ' + res.statusText + '][' + fetch_url + '] is reachable but NOT OK (not 200)';
+ _ret.size = res.size;
+ _ret.err = true; // make it true rather than null
+ }
+ // _log_return(_ret);
+ // return callback(_ret);
+ return res.text();
+ })
+ .then(function(body) {
+ _ret.body = body;
+ // _log_return(_ret);
+ return callback(_ret);
+ })
+ .catch((err) => {
_ret.ok = false;
_ret.status = CHECK_FAIL;
- _ret.result = '[HTTP: ' + res.status + ': ' + res.statusText + '][' + fetch_url + '] is reachable but NOT OK (not 200)';
- _ret.size = res.size;
- _ret.err = true; // make it true rather than null
- }
- // _log_return(_ret);
- // return callback(_ret);
- return res.text();
- })
- .then(function(body) {
- _ret.body = body;
- // _log_return(_ret);
- return callback(_ret);
- })
- .catch(err => {
- _ret.ok = false;
- _ret.status = CHECK_FAIL;
- _ret.result = '[HTTP: ' + err.message + '][' + fetch_url + '] is unreachable';
- _ret.size = -1;
- _ret.err = err;
- // _log_return(_ret);
- return callback(_ret);
- });
- } catch(err) {
+ _ret.result = '[HTTP: ' + err.message + '][' + fetch_url + '] is unreachable';
+ _ret.size = -1;
+ _ret.err = err;
+ // _log_return(_ret);
+ return callback(_ret);
+ });
+ } catch (err) {
_ret.ok = false;
_ret.status = CHECK_FAIL;
_ret.result = '[HTTP: ' + err.message + '][' + fetch_url + '] is unreachable';
@@ -1302,7 +1302,7 @@ function make_robots_txt_url(uri) {
// log and pass - for now: do not crash and burn if the URL is broken!!
if ((!parsed.protocol) || (!parsed.host)) {
// throw new Error('Cannot parse URL: ' + uri);
- console.log('==> ERROR: Cannot parse URL: ' + uri);
+ console.log('==> ERROR: Cannot parse URL: ' + uri);
}
return [
@@ -1332,8 +1332,8 @@ function check_robots_txt(validation_url, callback) {
'Googlebot-Smartphone [' + check_robots_txt_ua_googlebot_smartphone_ok + '] ';
check_robots_txt_results
= build_result_extras
- ? check_robots_txt_results + '[' + build_result_extras + ']'
- : check_robots_txt_results;
+ ? check_robots_txt_results + '[' + build_result_extras + ']'
+ : check_robots_txt_results;
if (check_robots_txt_file_url_404) {
check_robots_txt_status = CHECK_PASS;
} else {
@@ -1358,7 +1358,7 @@ function check_robots_txt(validation_url, callback) {
// console.log('=> [robots.txt] ' + check_robots_txt_file_url);
// console.log('=> [Googlebot] ' + check_robots_txt_ua_googlebot_ok + ': ' + url);
// console.log('=> [Googlebot-Smartphone] ' + check_robots_txt_ua_googlebot_smartphone_ok + ': ' + url);
- };
+ }
function url_is_reachable_callback(_ret) {
// return object: _ret = {
@@ -1398,23 +1398,23 @@ function check_robots_txt(validation_url, callback) {
let site_map_cnt = site_maps.length;
site_maps
= site_maps[0]
- ? 'site maps (' + site_map_cnt + '): ' + site_maps[0]
- : null;
+ ? 'site maps (' + site_map_cnt + '): ' + site_maps[0]
+ : null;
let build_result_extras = site_maps || null;
// UA_GOOGLEBOT
check_robots_txt_ua_googlebot_ok
= robots.isAllowed(validation_url, UA_GOOGLEBOT)
- ? CHECK_PASS : CHECK_FAIL;
+ ? CHECK_PASS : CHECK_FAIL;
// UA_GOOGLEBOT_SMARTPHONE
check_robots_txt_ua_googlebot_smartphone_ok
= robots.isAllowed(validation_url, UA_GOOGLEBOT_SMARTPHONE)
- ? CHECK_PASS : CHECK_FAIL;
+ ? CHECK_PASS : CHECK_FAIL;
build_results(build_result_extras);
callback(check_robots_txt_return);
} catch (err) {
- console.log('==> ERROR: check_robots_txt(validation_url): ' + validation_url);
- console.log('==> ERROR: check_robots_txt(err) : ' + err);
+ console.log('==> ERROR: check_robots_txt(validation_url): ' + validation_url);
+ console.log('==> ERROR: check_robots_txt(err) : ' + err);
check_robots_txt_ua_googlebot_ok = CHECK_FAIL;
check_robots_txt_ua_googlebot_smartphone_ok = CHECK_FAIL;
build_results(err);
@@ -1436,8 +1436,8 @@ function check_robots_txt(validation_url, callback) {
function check_google_amp_cache(url, callback) {
const
- url_cdn = make_url_to_google_amp_cache(url),
- url_viewer = make_url_to_google_amp_viewer(url);
+ url_cdn = make_url_to_google_amp_cache(url),
+ url_viewer = make_url_to_google_amp_viewer(url);
let check_google_amp_cache_return = {},
check_google_amp_cache_status = '',
@@ -1448,7 +1448,7 @@ function check_google_amp_cache(url, callback) {
let _stamp_on_begin = new Date(); // set beginning timestamp
- request( { uri: url_cdn, headers: {'User-Agent': UA_AMPBENCH} }, (err, res, body) => {
+ request( { uri: url_cdn, headers: { 'User-Agent': UA_AMPBENCH } }, (err, res, body) => {
if (!err) {
if (res.statusCode == 200) {
duration_in_milliseconds = new Date() - _stamp_on_begin;
@@ -1486,7 +1486,7 @@ function check_google_amp_cache(url, callback) {
function check_google_amp_viewer(url, callback) {
- const url_viewer = make_url_to_google_amp_viewer(url);
+ const url_viewer = make_url_to_google_amp_viewer(url);
let check_google_amp_viewer_return = {},
check_google_amp_viewer_status = '',
@@ -1495,7 +1495,7 @@ function check_google_amp_viewer(url, callback) {
let _stamp_on_begin = new Date(); // set beginning timestamp
- request( { uri: url_viewer, headers: {'User-Agent': UA_AMPBENCH} }, (err, res, body) => {
+ request( { uri: url_viewer, headers: { 'User-Agent': UA_AMPBENCH } }, (err, res, body) => {
if (!err) {
if (res.statusCode == 200) {
duration_in_milliseconds = new Date() - _stamp_on_begin;
@@ -1544,7 +1544,7 @@ function check_redirects_for_mobile(url, callback) {
const req = request(options, (err, res, body) => {
href_request = url;
- if (typeof(res) == "undefined") {
+ if (typeof (res) == 'undefined') {
check_redirects_status = CHECK_FAIL;
check_redirects_results = err.message;
// href_request = req.uri.href;
@@ -1669,7 +1669,7 @@ function parse_body_for_amplinks(body, http_response) {
if ('canonical' === rel || 'amphtml' === rel) {
href_url = $(link).attr('href');
- href = {rel: rel, url: href_url};
+ href = { rel: rel, url: href_url };
if ('canonical' === rel) {
// only take the first occurrence
__return.canonical_url = encodeURI('' === __return.canonical_url
@@ -1695,10 +1695,10 @@ function parse_body_for_amplinks_and_robots_metatags(http_response) {
const
__links = parse_body_for_amplinks(http_response.http_response_body, http_response);
const
- canonical_url = __links.canonical_url,
- amphtml_url = __links.amphtml_url,
- amphtml_urls = __links.amphtml_urls,
- has_dns_prefetch = __links.has_dns_prefetch;
+ canonical_url = __links.canonical_url,
+ amphtml_url = __links.amphtml_url,
+ amphtml_urls = __links.amphtml_urls,
+ has_dns_prefetch = __links.has_dns_prefetch;
let check_robots_meta_status = CHECK_PASS,
check_robots_meta_result = '';
@@ -1717,7 +1717,7 @@ function parse_body_for_amplinks_and_robots_metatags(http_response) {
$(metas).each( (i, meta) => {
// meta_name = ($(meta).attr('name')).toString().toLowerCase();
meta_name = $(meta).attr('name');
- meta_name = (typeof(meta_name) == "undefined") ? '' : meta_name.toString().toLowerCase();
+ meta_name = (typeof (meta_name) == 'undefined') ? '' : meta_name.toString().toLowerCase();
if ('robots' === meta_name ||
'googlebot' === meta_name ||
'googlebot-mobile' === meta_name ||
@@ -1745,11 +1745,11 @@ function parse_body_for_amplinks_and_robots_metatags(http_response) {
// console.log('=> [check_robots_meta_result: ' + check_robots_meta_result + ']');
return {
- canonical_url: canonical_url,
- amphtml_url: amphtml_url,
- amphtml_urls: amphtml_urls,
- has_dns_prefetch: has_dns_prefetch,
- amp_uses_feed: (-1 < http_response.url.indexOf('googleusercontent.com/amphtml')),
+ canonical_url: canonical_url,
+ amphtml_url: amphtml_url,
+ amphtml_urls: amphtml_urls,
+ has_dns_prefetch: has_dns_prefetch,
+ amp_uses_feed: (-1 < http_response.url.indexOf('googleusercontent.com/amphtml')),
check_robots_meta_status: check_robots_meta_status,
check_robots_meta_result: check_robots_meta_result
};
@@ -1827,7 +1827,7 @@ function parse_headers_for_x_robots_tag(http_response) {
check_x_robots_tag_header_status: CHECK_FAIL
};
- if (typeof(http_response.response.headers['x-robots-tag']) === "undefined") {
+ if (typeof (http_response.response.headers['x-robots-tag']) === 'undefined') {
check_x_robots_tag_header.check_x_robots_tag_header_results = 'X-Robots-Tag header check appears to be OK';
check_x_robots_tag_header.check_x_robots_tag_header_status = CHECK_PASS;
} else {
@@ -1854,7 +1854,7 @@ function parse_headers_for_if_modified_since_or_etag(http_response) {
if (http_response && http_response.response && http_response.response.headers &&
typeof http_response.response.headers !== 'undefined') {
- if (typeof(http_response.response.headers['if-modified-since']) === "undefined") {
+ if (typeof (http_response.response.headers['if-modified-since']) === 'undefined') {
check_ims_or_etag_header.check_ims_header_result = 'Header entry for If-Modified-Since not found';
check_ims_or_etag_header.check_ims_header_status = CHECK_INFO;
} else {
@@ -1863,7 +1863,7 @@ function parse_headers_for_if_modified_since_or_etag(http_response) {
check_ims_or_etag_header.check_ims_header_status = CHECK_PASS;
}
- if (typeof(http_response.response.headers['etag']) === "undefined") {
+ if (typeof (http_response.response.headers['etag']) === 'undefined') {
check_ims_or_etag_header.check_etag_header_result = 'Header entry for ETag not found';
check_ims_or_etag_header.check_etag_header_status = CHECK_INFO;
} else {
@@ -1949,7 +1949,7 @@ function make_url_to_google_amp_cache(url) {
// }
function make_url_to_google_amp_viewer(url) {
- const AMP_VIEWER_HTTP = 'https://www.google.com/amp/';
+ const AMP_VIEWER_HTTP = 'https://www.google.com/amp/';
const AMP_VIEWER_HTTPS = 'https://www.google.com/amp/s/';
var url_viewer = '';
if (url.startsWith('http://')) {
@@ -1988,14 +1988,14 @@ function make_url_validate_href(url, title) {
// prod: https://ampbench.appspot.com/
// Open in a new tab...
// const pref = '';
- return pref + suff;
+ return pref + suff;
}
function make_url_href(url, title) {
- const pref = '';
+ const pref = '';
return pref + suff;
}
@@ -2017,7 +2017,7 @@ function multiline_to_html(multiline_str) { // convert os.EOL to HTML line-break
// console.log('=> multiline_str:\n' + multiline_str);
if (multiline_str) {
if (-1 !== multiline_str.indexOf(os.EOL)) {
- var h = multiline_str.split(os.EOL).join("
");
+ var h = multiline_str.split(os.EOL).join('
');
// return '' + h + '
';
return ('' + h + '
');
}
@@ -2045,15 +2045,15 @@ function str_rtrim_char(str, char) {
return str_ret;
}
-function unwrap_js_object(obj, maxDepth, prefix){
+function unwrap_js_object(obj, maxDepth, prefix) {
var result = '';
- if (!prefix) prefix='';
- for(var key in obj){
+ if (!prefix) {prefix = '';}
+ for (var key in obj) {
if (typeof obj[key] === 'object') {
if (maxDepth !== undefined && maxDepth <= 1) {
result += (prefix + key + '=object [max depth reached]\n');
} else {
- result += unwrap_js_object(obj[key], (maxDepth) ? maxDepth - 1: maxDepth, prefix + key + '.');
+ result += unwrap_js_object(obj[key], (maxDepth) ? maxDepth - 1 : maxDepth, prefix + key + '.');
}
} else {
result += (prefix + key + '=' + obj[key] + '\n');
diff --git a/ampbench_lib_sd.js b/ampbench_lib_sd.js
index 68c05f8..f6488f1 100755
--- a/ampbench_lib_sd.js
+++ b/ampbench_lib_sd.js
@@ -18,7 +18,7 @@ const http_status = require('http-status');
const cheerio = require('cheerio');
const microdata = require('microdata-node');
const util = require('util');
-const inspect_obj = (obj) => {return util.inspect(obj, { showHidden: true, depth: null })};
+const inspect_obj = (obj) => {return util.inspect(obj, { showHidden: true, depth: null });};
const S = require('string');
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -51,16 +51,16 @@ const
AMP_SD_TYPES_WEBPAGE = ['WebPage'];
const
- sd_type_is_amp = type => {
+ sd_type_is_amp = (type) => {
return AMP_SD_TYPES.indexOf(type) !== -1 ? CHECK_PASS : CHECK_FAIL;
},
- sd_type_is_amp_article = type => {
+ sd_type_is_amp_article = (type) => {
return AMP_SD_TYPES_ARTICLE.indexOf(type) !== -1;
},
- sd_type_is_amp_article_companion_type = type => {
+ sd_type_is_amp_article_companion_type = (type) => {
return AMP_SD_TYPES_ARTICLE_COMPANIONS.indexOf(type) !== -1;
},
- sd_type_is_amp_recipe = type => {
+ sd_type_is_amp_recipe = (type) => {
return AMP_SD_TYPES_RECIPE.indexOf(type) !== -1;
};
@@ -92,19 +92,19 @@ class MetaData {
}
print() {
const puts = console.log;
- puts('=> metadata.json_error : ' + this.json_error);
- puts('=> metadata.kind : ' + this.kind);
- puts('=> metadata.type : ' + this.type);
- puts('=> metadata.type_is_amp : ' + this.type_is_amp);
- puts('=> metadata.status : ' + this.status);
- puts('=> metadata.result : ' + this.result);
- puts('=> metadata.context : ' + this.context);
+ puts('=> metadata.json_error : ' + this.json_error);
+ puts('=> metadata.kind : ' + this.kind);
+ puts('=> metadata.type : ' + this.type);
+ puts('=> metadata.type_is_amp : ' + this.type_is_amp);
+ puts('=> metadata.status : ' + this.status);
+ puts('=> metadata.result : ' + this.result);
+ puts('=> metadata.context : ' + this.context);
}
print_json() {
console.log('=> metadata.json_error: ' + this.json_error);
console.log('=> metadata.json_text:\n' + this.json_text);
console.log('=> metadata.json: typeof: ' + typeof this.json);
- console.log('=> metadata.json:\n' + JSON.stringify(this.json, null, 4));
+ console.log('=> metadata.json:\n' + JSON.stringify(this.json, null, 4));
}
print_json_text() {
console.log('=> metadata.json_text:\n' + this.json_text);
@@ -114,11 +114,11 @@ class MetaData {
class RecipeMetaData extends MetaData {
constructor() {
super();
- this.name = ''; // REQUIRED!!!
+ this.name = ''; // REQUIRED!!!
this.image = ''; // REQUIRED!!!
- this.author_name = ''; // recommended / warning
+ this.author_name = ''; // recommended / warning
this.datePublished = ''; // recommended / warning
- this.aggregateRating = { // recommended / warning
+ this.aggregateRating = { // recommended / warning
ratingValue: '',
reviewCount: ''
};
@@ -169,29 +169,29 @@ class ArticleMetaData extends MetaData {
print() {
super.print();
const puts = console.log;
- puts('=> metadata.news_headline : ' + this.news_headline);
- puts('=> metadata.author_name : ' + this.author_name);
- puts('=> metadata.publisher_name : ' + this.publisher_name);
- puts('=> metadata.date_published : ' + this.date_published);
- puts('=> metadata.date_modified : ' + this.date_modified);
- puts('=> metadata.image.type : ' + this.image.type);
- puts('=> metadata.image.url : ' + this.image.url);
- puts('=> metadata.image.url_status : ' + this.image.url_status);
- puts('=> metadata.image.file_type : ' + this.image.file_type);
- puts('=> metadata.image.width : ' + this.image.width);
- puts('=> metadata.image.height : ' + this.image.height);
- puts('=> metadata.image.status : ' + this.image.status);
- puts('=> metadata.image.result : ' + this.image.result);
- puts('=> metadata.article_image.type : ' + this.image.type);
- puts('=> metadata.article_image.url : ' + this.image.url);
- puts('=> metadata.article_image.url_status: ' + this.image.url_status);
- puts('=> metadata.article_image.file_type : ' + this.image.file_type);
- puts('=> metadata.article_image.width : ' + this.image.width);
- puts('=> metadata.article_image.height : ' + this.image.height);
- puts('=> metadata.article_image.status : ' + this.image.status);
- puts('=> metadata.article_image.result : ' + this.image.result);
- puts('=> metadata.article.status : ' + this.article.status);
- puts('=> metadata.article.result : ' + this.article.result);
+ puts('=> metadata.news_headline : ' + this.news_headline);
+ puts('=> metadata.author_name : ' + this.author_name);
+ puts('=> metadata.publisher_name : ' + this.publisher_name);
+ puts('=> metadata.date_published : ' + this.date_published);
+ puts('=> metadata.date_modified : ' + this.date_modified);
+ puts('=> metadata.image.type : ' + this.image.type);
+ puts('=> metadata.image.url : ' + this.image.url);
+ puts('=> metadata.image.url_status : ' + this.image.url_status);
+ puts('=> metadata.image.file_type : ' + this.image.file_type);
+ puts('=> metadata.image.width : ' + this.image.width);
+ puts('=> metadata.image.height : ' + this.image.height);
+ puts('=> metadata.image.status : ' + this.image.status);
+ puts('=> metadata.image.result : ' + this.image.result);
+ puts('=> metadata.article_image.type : ' + this.image.type);
+ puts('=> metadata.article_image.url : ' + this.image.url);
+ puts('=> metadata.article_image.url_status: ' + this.image.url_status);
+ puts('=> metadata.article_image.file_type : ' + this.image.file_type);
+ puts('=> metadata.article_image.width : ' + this.image.width);
+ puts('=> metadata.article_image.height : ' + this.image.height);
+ puts('=> metadata.article_image.status : ' + this.image.status);
+ puts('=> metadata.article_image.result : ' + this.image.result);
+ puts('=> metadata.article.status : ' + this.article.status);
+ puts('=> metadata.article.result : ' + this.article.result);
}
}
@@ -202,7 +202,7 @@ class ArticleMetaData extends MetaData {
// https://developers.google.com/structured-data/carousels/top-stories#2_make_your_amp_pages_easy_for_google_to_discover
const
- url_is_valid = url => {
+ url_is_valid = (url) => {
return benchlib.check_url_is_valid(url) ? CHECK_PASS : CHECK_FAIL;
};
@@ -298,31 +298,31 @@ function sd_publisher_logo_image_is_ok(url, width, height) {
else {
// image height - - - - - - - - - - - - - - - - - - - - -
if (height > 0 && height < 61) {
- h_stat = {status: CHECK_PASS, result: rule_desc_logo_dims};
+ h_stat = { status: CHECK_PASS, result: rule_desc_logo_dims };
sd_logo_image_result += '[height OK]';
}
else if (height > 60) {
- h_stat = {status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: height > 60]'};
+ h_stat = { status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: height > 60]' };
sd_logo_image_status = CHECK_FAIL;
sd_logo_image_result += '[invalid: height > 60]';
}
else {
- h_stat = {status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: height = 0 or is unavailable]'};
+ h_stat = { status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: height = 0 or is unavailable]' };
sd_logo_image_status = CHECK_FAIL;
sd_logo_image_result += '[invalid: height = 0 or is unavailable]';
}
// image width - - - - - - - - - - - - - - - - - - - - -
if (width > 0 && width < 601) {
- w_stat = {status: CHECK_PASS, result: rule_desc_logo_dims};
+ w_stat = { status: CHECK_PASS, result: rule_desc_logo_dims };
sd_logo_image_result += '[width OK]';
}
else if (width > 600) {
- w_stat = {status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: width > 600]'};
+ w_stat = { status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: width > 600]' };
sd_logo_image_status = CHECK_FAIL;
sd_logo_image_result += '[invalid: width > 600]';
}
else {
- w_stat = {status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: width = 0 or is unavailable]'};
+ w_stat = { status: CHECK_FAIL, result: rule_desc_logo_dims + '[invalid: width = 0 or is unavailable]' };
sd_logo_image_status = CHECK_FAIL;
sd_logo_image_result += '[invalid: width = 0 or is unavailable]';
}
@@ -410,7 +410,7 @@ function sd_article_image_is_ok(url, width, height) {
}
function check_image_urls_are_reachable(logo_url, image_url, callback) {
- let logo_url_is_reachable_ret = null,
+ let logo_url_is_reachable_ret = null,
image_url_is_reachable_ret = null;
// _ret = {
// url: fetch_url,
@@ -447,7 +447,7 @@ function check_body_metadata(body) {
function extract_metadata(body, metadata) {
- let md = extract_metadata_json_ld_article(body, metadata);
+ let md = extract_metadata_json_ld_article(body, metadata);
// console.log('- - extract_metadata - -');
// console.log('==> metadata.kind : ' + md.kind);
@@ -535,11 +535,11 @@ function extract_metadata_json_ld_news_types(body) { // cater for multiple ld+js
jsonld_script_return = JSON.stringify(jsonld_json);
}
}
- } catch(err) { // do nothing - we need to carry on
+ } catch (err) { // do nothing - we need to carry on
// console.log('==> ERROR: extract_json_ld: JSON.parse(jsonld_block): ' + err);
}
}
- } catch(err) { // do nothing - we need to carry on
+ } catch (err) { // do nothing - we need to carry on
// console.log('==> ERROR: extract_json_ld(): ' + err);
}
return jsonld_script_return;
@@ -592,10 +592,10 @@ function extract_metadata_json_ld_article(body, metadata) {
metadata.image.width = metadata.json.publisher.logo.width;
metadata.image.height = metadata.json.publisher.logo.height;
let publisher_logo_ok = sd_publisher_logo_image_is_ok(
- parse_image_url(metadata.image.url),
- metadata.image.width, metadata.image.height);
+ parse_image_url(metadata.image.url),
+ metadata.image.width, metadata.image.height);
metadata.image.file_type = publisher_logo_ok.sd_logo_image_results.file_type;
- metadata.image.status = publisher_logo_ok.sd_logo_image_status;
+ metadata.image.status = publisher_logo_ok.sd_logo_image_status;
metadata.image.result = publisher_logo_ok.sd_logo_image_result;
metadata.image.url_status = publisher_logo_ok.sd_logo_image_url_status;
@@ -614,10 +614,10 @@ function extract_metadata_json_ld_article(body, metadata) {
metadata.article_image.width = metadata.json.image.width;
metadata.article_image.height = metadata.json.image.height;
let article_logo_ok = sd_article_image_is_ok(
- parse_image_url(metadata.article_image.url),
- metadata.article_image.width, metadata.article_image.height);
+ parse_image_url(metadata.article_image.url),
+ metadata.article_image.width, metadata.article_image.height);
metadata.article_image.file_type = article_logo_ok.sd_logo_image_results.file_type;
- metadata.article_image.status = article_logo_ok.sd_logo_image_status;
+ metadata.article_image.status = article_logo_ok.sd_logo_image_status;
metadata.article_image.result = article_logo_ok.sd_logo_image_result;
metadata.article_image.url_status = article_logo_ok.sd_logo_image_url_status;
@@ -799,7 +799,7 @@ const unwrap_microdata_json_for_news = (md) => { // scans Microdata json block o
if (md_block_type) {
try { // DO NOT REMOVE!!! we need to carry on regardless of missing or invalid metadata items...
switch (md_block_type) {
-
+
case 'http://schema.org/Article':
case 'https://schema.org/Article':
case 'http://schema.org/NewsArticle':
@@ -907,7 +907,7 @@ function extract_metadata_microdata_news_types(metadata) { // scan for all news
function extract_metadata_microdata(metadata) {
try {
- if(0 < metadata.json.length) {
+ if (0 < metadata.json.length) {
metadata.kind = SD_MICRODATA;
metadata.status = CHECK_PASS;
@@ -938,19 +938,19 @@ function extract_metadata_microdata(metadata) {
try {
// publisher logo image metadata
let publisher_logo_ok = sd_publisher_logo_image_is_ok(
- parse_image_url(metadata.image.url),
- metadata.image.width, metadata.image.height);
+ parse_image_url(metadata.image.url),
+ metadata.image.width, metadata.image.height);
metadata.image.file_type = publisher_logo_ok.sd_logo_image_results.file_type;
- metadata.image.status = publisher_logo_ok.sd_logo_image_status;
+ metadata.image.status = publisher_logo_ok.sd_logo_image_status;
metadata.image.result = publisher_logo_ok.sd_logo_image_result;
metadata.image.url_status = publisher_logo_ok.sd_logo_image_url_status;
// // article image metadata //!!!TODO!!!20160524
let article_logo_ok = sd_article_image_is_ok(
- parse_image_url(metadata.article_image.url),
- metadata.article_image.width, metadata.article_image.height);
+ parse_image_url(metadata.article_image.url),
+ metadata.article_image.width, metadata.article_image.height);
metadata.article_image.file_type = article_logo_ok.sd_logo_image_results.file_type;
- metadata.article_image.status = article_logo_ok.sd_logo_image_status;
+ metadata.article_image.status = article_logo_ok.sd_logo_image_status;
metadata.article_image.result = article_logo_ok.sd_logo_image_result;
metadata.article_image.url_status = article_logo_ok.sd_logo_image_url_status;
@@ -979,12 +979,12 @@ function extract_metadata_microdata(metadata) {
metadata.result = 'Structured Data markup content appears to be invalid';
metadata.kind = SD_UNKNOWN;
}
- } catch(e) {
+ } catch (e) {
metadata.status = CHECK_FAIL;
metadata.result = 'Structured Data markup content appears to be invalid';
metadata.kind = SD_UNKNOWN;
}
- return metadata;
+ return metadata;
}
const extract_json_ld_items_from_body_if_badly_formed = (body, metadata) => {
@@ -1028,8 +1028,8 @@ const extract_json_ld_items_from_text_if_badly_formed = (metadata) => { // extra
metadata.image.height = S(temp).between('"height": ', '\n').s;
metadata.image.height = parseInt(metadata.image.height, 10);
let publisher_logo_ok = sd_publisher_logo_image_is_ok(
- parse_image_url(metadata.image.url),
- metadata.image.width, metadata.image.height);
+ parse_image_url(metadata.image.url),
+ metadata.image.width, metadata.image.height);
metadata.image.file_type = publisher_logo_ok.sd_logo_image_results.file_type;
metadata.image.status = publisher_logo_ok.sd_logo_image_status;
metadata.image.result = publisher_logo_ok.sd_logo_image_result;
@@ -1048,8 +1048,8 @@ const extract_json_ld_items_from_text_if_badly_formed = (metadata) => { // extra
metadata.article_image.height = S(temp).between('"height": ', '\n').s;
metadata.article_image.height = parseInt(metadata.article_image.height, 10);
let article_logo_ok = sd_article_image_is_ok(
- parse_image_url(metadata.article_image.url),
- metadata.article_image.width, metadata.article_image.height);
+ parse_image_url(metadata.article_image.url),
+ metadata.article_image.width, metadata.article_image.height);
metadata.article_image.file_type = article_logo_ok.sd_logo_image_results.file_type;
metadata.article_image.status = article_logo_ok.sd_logo_image_status;
metadata.article_image.result = article_logo_ok.sd_logo_image_result;
@@ -1085,12 +1085,12 @@ const extract_json_ld_items_from_text_if_badly_formed = (metadata) => { // extra
//
const last_element_of_list = (list) => {
- return list[list.length - 1];
+ return list[list.length - 1];
};
const last_element_of_path = (path) => {
- const path_str = path.toString();
- return path_str.substr(path_str.lastIndexOf('/') + 1);
+ const path_str = path.toString();
+ return path_str.substr(path_str.lastIndexOf('/') + 1);
};
function log_js_object(o, prefix) {
@@ -1103,13 +1103,13 @@ function log_js_object(o, prefix) {
function unwrap_js_object(obj, maxDepth, prefix) {
var result = '';
- if (!prefix) prefix='';
- for(var key in obj){
+ if (!prefix) {prefix = '';}
+ for (var key in obj) {
if (typeof obj[key] === 'object') {
if (maxDepth !== undefined && maxDepth <= 1) {
result += (prefix + key + '=object [max depth reached]\n');
} else {
- result += unwrap_js_object(obj[key], (maxDepth) ? maxDepth - 1: maxDepth, prefix + key + '.');
+ result += unwrap_js_object(obj[key], (maxDepth) ? maxDepth - 1 : maxDepth, prefix + key + '.');
}
} else {
result += (prefix + key + '=' + obj[key] + '\n');
diff --git a/ampbench_main.js b/ampbench_main.js
index b96ad7b..ea98ee9 100644
--- a/ampbench_main.js
+++ b/ampbench_main.js
@@ -20,7 +20,7 @@
const routes = require('./ampbench_routes.js');
if (module === require.main) {
- const server = routes.app.listen(process.env.PORT || 8080, function () {
+ const server = routes.app.listen(process.env.PORT || 8080, function() {
let __server = routes.init_server(server);
var host = __server.host;
var port = __server.port;
diff --git a/ampbench_routes.js b/ampbench_routes.js
index 6601782..ade1658 100644
--- a/ampbench_routes.js
+++ b/ampbench_routes.js
@@ -39,7 +39,7 @@ function consoleLogHostAndRemoteIP(req) {
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
console.log(
- '[HOST: ' + req.headers.host + '] [REMOTE-IP: ' + remote_ip + ']');
+ '[HOST: ' + req.headers.host + '] [REMOTE-IP: ' + remote_ip + ']');
}
function consoleLogRequest(req, check_http_response, amp_url) {
@@ -47,7 +47,7 @@ function consoleLogRequest(req, check_http_response, amp_url) {
console.log(version_msg(validator_signature()));
consoleLogHostAndRemoteIP(req);
console.log(
- '[HTTP: ' + check_http_response.http_response_code + '] ' +
+ '[HTTP: ' + check_http_response.http_response_code + '] ' +
req.path + ' ' + amp_url);
// console.log(
// '[BARE URL: ' + benchutil.get_bare_url(amp_url) + '] ');
@@ -62,9 +62,9 @@ function consoleLogRequestResponse(req, res) {
function ifdef(v) { // useful for outputting potentially undefined variable values
if (v)
- return v;
+ {return v;}
else
- return '';
+ {return '';}
}
function format_dashes(dash_count) { // needs: const S = require('string');
@@ -113,12 +113,12 @@ const
const os = require('os');
const fs = require('fs');
-const path = require("path");
+const path = require('path');
const http = require('http');
const https = require('https');
const url = require('url');
const util = require('util');
-const inspect_obj = (obj) => { return util.inspect(obj, { showHidden: true, depth: null }) };
+const inspect_obj = (obj) => { return util.inspect(obj, { showHidden: true, depth: null }); };
const S = require('string');
const express = require('express');
@@ -136,8 +136,8 @@ const index_template = fs.readFileSync(__dirname + '/views/index.hbs', 'utf8');
const results_template = fs.readFileSync(__dirname + '/views/results.hbs', 'utf8');
// Initialise handlebars helper to include gtag filtering.
handlebars.registerHelper('gtag', function(options) {
- if (process.env.GTAG_ID) {
- return options.fn({gtag_id: process.env.GTAG_ID});
+ if (process.env.GTAG_ID) {
+ return options.fn({ gtag_id: process.env.GTAG_ID });
}
});
@@ -205,7 +205,7 @@ app.use((err, req, res, next) => {
app.get('/', (req, res) => {
consoleLogRequestResponse(req, res);
- res.header("Content-Type", "text/html; charset=utf-8");
+ res.header('Content-Type', 'text/html; charset=utf-8');
res.write(handlebars.compile(index_template)());
res.end();
});
@@ -225,7 +225,7 @@ function assert_url(req, res) { // handle bad urls
let url_to_validate = req.query.url || '';
if (!benchlib.check_url_is_valid(url_to_validate)) {
console.log(version_msg(
- validator_signature() +
+ validator_signature() +
'[ERROR: INVALID URL] Please check the formatting of the requested URL: ' +
req.path + ' ' + url_to_validate));
let _err = {
@@ -266,7 +266,7 @@ app.get('/validate', (req, res) => {
consoleLogRequest(req, check_http_response, __ret.url);
// console.log(`### [check_http_response.statusIsOK: ${check_http_response.statusIsOK()}]`);
// if (check_http_response.statusIsOK()) {
- res.header("Content-Type", "text/html; charset=utf-8");
+ res.header('Content-Type', 'text/html; charset=utf-8');
if (__ret) {
res.write(handlebars.compile(results_template)(__ret));
res.end();
@@ -293,7 +293,7 @@ app.get('/validate_ua_desktop', (req, res) => {
let check_http_response = __ret.http_response;
consoleLogRequest(req, check_http_response, __ret.url);
// console.log(`### [check_http_response.statusIsOK: ${check_http_response.statusIsOK()}]`);
- res.header("Content-Type", "text/html; charset=utf-8");
+ res.header('Content-Type', 'text/html; charset=utf-8');
if (__ret) {
res.write(handlebars.compile(results_template)(__ret));
res.end();
@@ -704,7 +704,7 @@ app.get('/api2/', (req, res) => {
x_robots_tag_header_result: parse_amplinks.check_ims_or_etag_header_results
},
sd_validation: make_api_sd_validation(api_validate_sd_return)
- }
+ };
};
let write_api_response = () => {
@@ -779,4 +779,4 @@ exports.init_server = init_server;
exports.version_msg = version_msg;
exports.app = app;
-// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\ No newline at end of file
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/ampbench_util.js b/ampbench_util.js
index a77af55..760f316 100755
--- a/ampbench_util.js
+++ b/ampbench_util.js
@@ -13,24 +13,26 @@
'use strict';
+/* eslint no-unused-vars: 0 */
+
// use: import {get_bare_url, urls_are_similar} from 'ampbench_util'; !!!2018.09: NOT SUPPORTED BY NODE.JS YET!!!
const S = require('string');
const util = require('util');
function inspect_obj(obj) {
- return util.inspect(obj, { showHidden: true, depth: null })
+ return util.inspect(obj, { showHidden: true, depth: null });
}
function unwrap_js_object(obj, maxDepth, prefix) {
let result = '';
- if (!prefix) prefix='';
- for(let key in obj){
+ if (!prefix) {prefix = '';}
+ for (let key in obj) {
if (typeof obj[key] === 'object') {
if (maxDepth !== undefined && maxDepth <= 1) {
result += (prefix + key + '=object [max depth reached]\n');
} else {
- result += unwrap_js_object(obj[key], (maxDepth) ? maxDepth - 1: maxDepth, prefix + key + '.');
+ result += unwrap_js_object(obj[key], (maxDepth) ? maxDepth - 1 : maxDepth, prefix + key + '.');
}
} else {
result += (prefix + key + '=' + obj[key] + '\n');
@@ -56,7 +58,7 @@ function last_element_of_list(list) {
return list[list.length - 1];
}
-function last_element_of_path (path) {
+function last_element_of_path(path) {
const path_str = path.toString();
return path_str.substr(path_str.lastIndexOf('/') + 1);
}
@@ -78,7 +80,7 @@ function print_dashes(dash_count) { // needs: const S = require('string');
}
function make_url_href(url, title) {
- const pref = '';
return pref + suff;
}
@@ -99,8 +101,8 @@ function make_url_href_list(urls) {
function multiline_to_html(multiline_str) { // convert os.EOL to HTML line-breaks
// console.log('=> multiline_str:\n' + multiline_str);
if (multiline_str) {
- if (-1 !== multiline_str.indexOf(os.EOL)) {
- var h = multiline_str.split(os.EOL).join("
");
+ if (-1 !== multiline_str.indexOf(os.EOL)) { // eslint-disable-line no-undef
+ var h = multiline_str.split(os.EOL).join('
'); // eslint-disable-line no-undef
// return '' + h + '
';
return ('' + h + '
');
}
@@ -114,8 +116,8 @@ function get_bare_url(url) {
// test: 'xwp.co' === get_bare_url('https://xwp.co')
// test: 'xwp.co' === get_bare_url('https://xwp.co/')
let _url = url.trim();
- if ('/' === _url.slice(-1)) { // check last character of the url
- _url = _url.slice(0, -1); // remove last character of the url
+ if ('/' === _url.slice(-1)) { // check last character of the url
+ _url = _url.slice(0, -1); // remove last character of the url
}
if (-1 < _url.indexOf('http://')) {
_url = _url.substr(7);