catch typos near 'AUTOTITLE' (#34493)
Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import path from 'path'
|
||||
import { visit } from 'unist-util-visit'
|
||||
import { distance } from 'fastest-levenshtein'
|
||||
import { getPathWithoutLanguage, getVersionStringFromPath } from '../../path-utils.js'
|
||||
import { getNewVersionedPath } from '../../old-versions-utils.js'
|
||||
import patterns from '../../patterns.js'
|
||||
@@ -40,8 +41,21 @@ export default function rewriteLocalLinks(context) {
|
||||
node.properties.href = newHref
|
||||
}
|
||||
for (const child of node.children) {
|
||||
if (child.value && AUTOTITLE.test(child.value)) {
|
||||
promises.push(getNewTitleSetter(child, node.properties.href, context))
|
||||
if (child.value) {
|
||||
if (AUTOTITLE.test(child.value)) {
|
||||
promises.push(getNewTitleSetter(child, node.properties.href, context))
|
||||
} else if (process.env.NODE_ENV !== 'production') {
|
||||
// Throw if the link text *almost* is AUTOTITLE
|
||||
if (
|
||||
child.value.toUpperCase() === 'AUTOTITLE' ||
|
||||
distance(child.value.toUpperCase(), 'AUTOTITLE') <= 2
|
||||
) {
|
||||
throw new Error(
|
||||
`Found link text '${child.value}', expected 'AUTOTITLE'. ` +
|
||||
`Find the mention of the link text '${child.value}' and change it to 'AUTOTITLE'. Case matters.`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user