1
0
mirror of synced 2025-12-22 03:16:52 -05:00

catch typos near 'AUTOTITLE' (#34493)

Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com>
This commit is contained in:
Peter Bengtsson
2023-02-07 12:22:44 -05:00
committed by GitHub
parent f99da59c05
commit d7b52e772d
8 changed files with 88 additions and 6 deletions

View File

@@ -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.`
)
}
}
}
}
})