// Warning : the original spofcheck works with an old version of Node. 0.10.36 did it for me. | |
// npm install spofcheck before | |
// For CLI display only : the original spofcheck could also generate a junit.xml file to be used in continuous integration | |
const spofcheck = require('spofcheck') | |
const url = require('url') | |
const Table = require('cli-table') | |
const URLs = [ | |
'http://www.vanityfair.fr/', | |
// 'http://www.vanityfair.fr/video', | |
// 'http://www.vanityfair.fr/actualites/international/diaporama/le-brexit-vu-par-la-presse-du-monde-entier/35191#daily-news', | |
// 'http://www.vanityfair.fr/video/actu/playlist/euro-2016-les-meilleures-videos-des-supporters-irlandais/1013#un-homme-fait-le-bonheur-de-supporters-irlandais-du-haut-de-son-balcon', | |
] | |
const domainsWhiteList = {} | |
spofcheck.run(URLs) | |
.then(function (results) { | |
console.log('analyzed ' + results.length + ' URLs', URLs) | |
results.forEach(function(result){ | |
var currentUrl = result.url | |
console.log('========') | |
console.log('domaines génants et scores de bonne pratique pour la page', currentUrl) | |
const filteredResults = [] | |
// console.log( 'score', ' domaine ', ' ressource') | |
var mainDomain = url.parse(currentUrl).hostname | |
domainsWhiteList[mainDomain] = mainDomain | |
result.messages.forEach(function(message){ | |
var fullURL = url.resolve(currentUrl, message.entity) | |
var domain = url.parse(fullURL).hostname | |
// on exclut l'analyse sur les doaines connus | |
if(domain in domainsWhiteList) | |
return | |
// console.log( '', message.score, ' ', domain, ' ', fullURL/*, , message */) | |
filteredResults.push([message.score, domain, fullURL]) | |
}) | |
// préparation de l'affichage en colonnes | |
var tableData = new Table({ | |
head: ['Score', 'Domain Name', 'URL'], | |
}) | |
// sort by score (worst first) | |
tableData.push.apply(tableData, filteredResults.sort(function (a, b) { | |
return a[0] - b[0] | |
}) ) | |
console.log(tableData.toString()) | |
}) | |
// console.log(JSON.stringify(results)); | |
}, function (errorObject) { | |
console.log(errorObject.message) | |
}) | |
.catch(function(error) { | |
console.trace(error) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment