LinkChecker and better linksToSkip function (#23001)
* LinkChecker and better linksToSkip function Part of #1253 * try now * escaped * make sure it skips all non-english links * feedbacked
This commit is contained in:
@@ -52,7 +52,7 @@ program
|
||||
// Skip non-English content.
|
||||
const languagesToSkip = Object.keys(libLanguages)
|
||||
.filter((code) => code !== 'en')
|
||||
.map((code) => `${root}/${code}`)
|
||||
.map((code) => new RegExp(`${root}/${code}`))
|
||||
|
||||
// Skip deprecated Enterprise content.
|
||||
// Capture the old format https://docs.github.com/enterprise/2.1/
|
||||
@@ -66,7 +66,19 @@ const config = {
|
||||
recurse: !program.opts().dryRun,
|
||||
silent: true,
|
||||
// The values in this array are treated as regexes.
|
||||
linksToSkip: [enterpriseReleasesToSkip, ...languagesToSkip, ...excludedLinks],
|
||||
linksToSkip: linksToSkipFactory([enterpriseReleasesToSkip, ...languagesToSkip, ...excludedLinks]),
|
||||
}
|
||||
|
||||
// Return a function that can as quickly as possible check if a certain
|
||||
// href input should be skipped.
|
||||
// Do this so we can use a `Set` and a `iterable.some()` for a speedier
|
||||
// check. The default implementation in Linkinator, if you set
|
||||
// the `linksToSkip` config to be an array, it will, for every URL it
|
||||
// checks turn that into a new regex every single time.
|
||||
function linksToSkipFactory(regexAndURLs) {
|
||||
const set = new Set(regexAndURLs.filter((regexOrURL) => typeof regexOrURL === 'string'))
|
||||
const regexes = regexAndURLs.filter((regexOrURL) => regexOrURL instanceof RegExp)
|
||||
return (href) => set.has(href) || regexes.some((regex) => regex.test(href))
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user