mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
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:
parent
b079514877
commit
fa90b25b3e
@ -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;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -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} />;
|
||||
}
|
Loading…
Reference in New Issue
Block a user