hexo-broken-links-checker
Advanced tools
Comparing version 1.0.2 to 1.1.0
hexo.config.broken_links_checker = Object.assign( | ||
{ | ||
enable: true, | ||
head: true, | ||
frontmatter: [], | ||
@@ -5,0 +6,0 @@ exclude: [], |
const fetch = require('node-fetch'); | ||
const checkLink = async (url, timeout) => { | ||
return new Promise((resolve, reject) => { | ||
fetch(url, { timeout: timeout || 0 }) | ||
.then(({ status, ok }) => { | ||
if (ok) { | ||
resolve(status); | ||
const runQuery = (url, method, timeout, resolve, reject) => { | ||
fetch(url, { method, timeout }) | ||
.then(({ status, ok }) => { | ||
if (ok) { | ||
resolve(status); | ||
} else { | ||
if (method === 'HEAD') { | ||
runQuery(url, 'GET', timeout, resolve, reject); | ||
} else { | ||
reject(status); | ||
} | ||
}) | ||
.catch((err) => reject(err)); | ||
}); | ||
} | ||
}) | ||
.catch((err) => { | ||
if (method === 'HEAD') { | ||
runQuery(url, 'GET', timeout, resolve, reject); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}; | ||
const checkLink = async (url, head, timeout) => | ||
new Promise((resolve, reject) => { | ||
runQuery(url, head ? 'HEAD' : 'GET', timeout || 0, resolve, reject); | ||
}); | ||
module.exports = { checkLink }; |
@@ -14,3 +14,3 @@ const { magenta, blue, red } = require('chalk'); | ||
if (config.broken_links_checker) { | ||
const { enable, exclude, frontmatter, timeout } = config.broken_links_checker; | ||
const { enable, head, exclude, frontmatter, timeout } = config.broken_links_checker; | ||
@@ -70,3 +70,3 @@ if (enable) { | ||
log.info('Checking URL: %s', magenta(url)); | ||
await checkLink(url, timeout); | ||
await checkLink(url, head, timeout); | ||
} else { | ||
@@ -87,2 +87,4 @@ log.info('URL check skip: %s', magenta(url)); | ||
throw new Error(`${brokenLinks.length} external link(s) are broken.`); | ||
} else { | ||
log.info('URL check is done. All links are alive.'); | ||
} | ||
@@ -89,0 +91,0 @@ }); |
{ | ||
"name": "hexo-broken-links-checker", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Broken links checker for Hexo static site generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8965
172