optimization: hash lookup is faster than in-array check (#23079)
This commit is contained in:
@@ -10,7 +10,7 @@ import removeFPTFromPath from '../../remove-fpt-from-path.js'
|
|||||||
import readJsonFile from '../../read-json-file.js'
|
import readJsonFile from '../../read-json-file.js'
|
||||||
const supportedVersions = Object.keys(allVersions)
|
const supportedVersions = Object.keys(allVersions)
|
||||||
const supportedPlans = Object.values(allVersions).map((v) => v.plan)
|
const supportedPlans = Object.values(allVersions).map((v) => v.plan)
|
||||||
const externalRedirects = Object.keys(readJsonFile('./lib/redirects/external-sites.json'))
|
const externalRedirects = readJsonFile('./lib/redirects/external-sites.json')
|
||||||
|
|
||||||
// Matches any <a> tags with an href that starts with `/`
|
// Matches any <a> tags with an href that starts with `/`
|
||||||
const matcher = (node) =>
|
const matcher = (node) =>
|
||||||
@@ -41,7 +41,7 @@ function getNewHref(node, languageCode, version) {
|
|||||||
// Exceptions to link rewriting
|
// Exceptions to link rewriting
|
||||||
if (href.startsWith('/assets')) return
|
if (href.startsWith('/assets')) return
|
||||||
if (href.startsWith('/public')) return
|
if (href.startsWith('/public')) return
|
||||||
if (externalRedirects.includes(href)) return
|
if (href in externalRedirects) return
|
||||||
|
|
||||||
let newHref = href
|
let newHref = href
|
||||||
// If the link has a hardcoded plan or version in it, do not update other than adding a language code
|
// If the link has a hardcoded plan or version in it, do not update other than adding a language code
|
||||||
|
|||||||
Reference in New Issue
Block a user