refactor(i18n): remove obsolete link lookup

This commit is contained in:
pku-xht
2026-08-18 20:19:38 +08:00
parent df11a8af92
commit f6fb074036
2 changed files with 9 additions and 18 deletions
+9 -6
View File
@@ -20,7 +20,6 @@ import {
blobHash,
isTranslationScopeFile,
languageSwitcherTargets,
linksTo,
pairAnchorOfArgument,
parseTranslationMarkdown,
parseTranslationPairingCliArgs,
@@ -187,17 +186,21 @@ describe('translation pairing switchers', () => {
const targets = languageSwitcherTargets('python/sdk/README.zh.md')
const canonicalMarkdown = '# README\n\nEnglish | [中文](https://github.com/deepseek-ai/deepseek-harness/blob/master/python/sdk/README.zh.md)\n'
const canonical = parseTranslationMarkdown(canonicalMarkdown)
const wrongPath = parseTranslationMarkdown(
'[中文](https://github.com/deepseek-ai/deepseek-harness/blob/master/other/README.zh.md)',
)
const wrongMarkdown = '# README\n\nEnglish | [中文](https://github.com/deepseek-ai/deepseek-harness/blob/master/other/README.zh.md)\n'
const wrongPath = parseTranslationMarkdown(wrongMarkdown)
expect(linksTo(canonical, targets)).toBe(true)
expect(translationStructureSignature(canonical, targets, {
repoRoot: process.cwd(),
sourcePath: 'python/sdk/README.md',
markdown: canonicalMarkdown,
}).links).toEqual([])
expect(linksTo(wrongPath, targets)).toBe(false)
expect(translationStructureSignature(wrongPath, targets, {
repoRoot: process.cwd(),
sourcePath: 'python/sdk/README.md',
markdown: wrongMarkdown,
}).links).toEqual([
'https://github.com/deepseek-ai/deepseek-harness/blob/master/other/README.zh.md',
])
})
it('excludes only the header switcher from the structural links', () => {
-12
View File
@@ -314,18 +314,6 @@ export function languageSwitcherTargets(counterpart: string): string[] {
return [basename(counterpart), `${PUBLIC_REPOSITORY_BLOB_ROOT}${counterpart}`]
}
/** Whether the tree contains a link to any accepted target. */
export function linksTo(tree: Nodes, targets: string | readonly string[]): boolean {
const accepted = new Set(typeof targets === 'string' ? [targets] : targets)
let found = false
const visit = (node: Nodes): void => {
if (node.type === 'link' && accepted.has(node.url)) found = true
if ('children' in node) for (const child of node.children) visit(child)
}
visit(tree)
return found
}
/** Generated English sources cannot carry a switcher without making their generator stale. */
export function requiresSourceLanguageSwitcher(source: string): boolean {
return ![