Revert "docs: auto trans link" (#42373)

* Revert "docs: auto trans link (#42311)"

This reverts commit e28c9237d6.

* Apply suggestions from code review

---------

Co-authored-by: afc163 <afc163@gmail.com>
This commit is contained in:
lijianan 2023-05-15 21:22:52 +08:00 committed by GitHub
parent b079514877
commit fa90b25b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 45 deletions

View File

@ -1,5 +1,5 @@
import assert from 'assert';
import { unistUtilVisit, type HastRoot, type UnifiedTransformer } from 'dumi';
import { type HastRoot, type UnifiedTransformer, unistUtilVisit } from 'dumi';
/**
* plugin for modify hast tree when docs compiling
@ -60,9 +60,6 @@ function rehypeAntd(): UnifiedTransformer<HastRoot> {
if (!node.properties) return;
node.properties.className ??= [];
(node.properties.className as string[]).push('component-api-table');
} else if (node.type === 'element' && (node.tagName === 'Link' || node.tagName === 'a')) {
node.tagName = 'LocaleLink';
node.properties.sourceType = node.tagName;
}
});
};

View File

@ -1,41 +0,0 @@
import { Link } from 'dumi';
import * as React from 'react';
import useLocale from '../../../hooks/useLocale';
type LinkProps = Parameters<typeof Link>[0];
export interface LocaleLinkProps extends LinkProps {
sourceType: 'a' | 'Link';
children?: React.ReactNode;
}
export default function LocaleLink({ sourceType, to, ...props }: LocaleLinkProps) {
const Component = sourceType === 'a' ? 'a' : Link;
const [, localeType] = useLocale();
const localeTo = React.useMemo(() => {
if (!to || typeof to !== 'string') {
return to;
}
// Auto locale switch
const cells = to.match(/(\/[^#]*)(#.*)?/);
if (cells) {
let path = cells[1].replace(/\/$/, '');
const hash = cells[2] || '';
if (localeType === 'cn' && !path.endsWith('-cn')) {
path = `${path}-cn`;
} else if (localeType === 'en' && path.endsWith('-cn')) {
path = path.replace(/-cn$/, '');
}
return `${path}${hash}`;
}
return to;
}, [to]);
return <Component to={localeTo} {...props} />;
}