Skip to content

Commit

Permalink
Update checkLink.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tea3 authored Aug 13, 2020
1 parent 8daa0c4 commit 7460f01
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/checkLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ const lr = require('./linkReplacer.js')

async function checkURL( res ){
let brokenLinks = []
let checkedExtURL = []
let brokenLinks_log = ``

// --------------------------------
// check the external links
// --------------------------------
for(let url of res.checkData.links.external){
if(!checkExclusionURL(url, res.hexo)){
const urlStat = await checkStatusCode( lr.amazonReplace(url) )
if( urlStat[0] != 200 ){
brokenLinks.push({
status: urlStat[0] ,
url: urlStat[1] ,
source: res.checkData.source ,
path: res.checkData.path
})
if(checkedExtURL.indexOf(url) == -1){
checkedExtURL.push(url)
const urlStat = await checkStatusCode( lr.amazonReplace(url) , res.checkData.source, res.hexo.config.autoLinkChecker.verbose )
if( urlStat[0] != 200 ){
brokenLinks.push({
status: urlStat[0] ,
url: urlStat[1] ,
source: res.checkData.source ,
path: res.checkData.path
})
}
}
}
}
Expand Down Expand Up @@ -107,8 +111,8 @@ async function checkURL( res ){
return res
}

const checkStatusCode = (url) => {
// console.log(`checking link : ${url}`)
const checkStatusCode = (url, checkingListData, isVerbose) => {
if(isVerbose)console.log(`\u001b[37m[hexo-auto-link-checker]\u001b[0m checking link ... \npath: ${checkingListData} \nurl: ${url}`)
return new Promise((resolve, reject) => {
request( url , (err, res, body) => {
if(err){
Expand Down

0 comments on commit 7460f01

Please sign in to comment.