docs: increase performance by using HEAD instead of GET

- bypass checking download.cypress.io
- normalize href’s so we don’t request dupes
This commit is contained in:
Brian Mann
2017-06-16 15:39:40 -04:00
parent e5dd194519
commit ee751d020a
+19 -1
View File
@@ -57,16 +57,26 @@ function assertHashIsPresent (descriptor, source, hash, html, tag = 'url') {
`)
}
const hrefs = []
function isTimeoutError (err) {
return err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT'
}
function validateExternalUrl (href, source) {
const { hash } = url.parse(href)
const { hash, hostname } = url.parse(href)
const started = new Date()
// don't check download.cypress.io
if (hostname === 'download.cypress.io') {
return Promise.resolve()
}
hrefs.push(href)
return request({
method: hash ? 'GET' : 'HEAD', // if we have a hash, use GET, else HEAD
url: href,
timeout: 5000,
})
@@ -208,6 +218,14 @@ function validateAndGetUrl (sidebar, href, source, text, render) {
)
}
// parse this into fully qualified url
// so we normalize values like
// http://foo.com
// http://foo.com/
const parsed = url.parse(href)
href = parsed.href
// do we already have a cache for this href?
const cachedValue = cache[href]