Skip to content

Commit

Permalink
refactor: support multiple version docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Apr 9, 2024
1 parent 48ab055 commit 358b44a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
12 changes: 8 additions & 4 deletions .dumi/components/Redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import { Spin } from 'antd';
import { useLocale } from 'dumi';
import { useEffect } from 'react';

export const Redirect = ({ url }: { url: string }) => {
export const Redirect = ({ url, target, text }: { url: string; target?: string; text?: string; }) => {
const { id: lang } = useLocale();
const loading = target !== '_blank';

useEffect(() => {
window.location.replace(url);
if (target === '_blank') {
window.open(url);
}
else window.location.replace(url);
}, []);

return (
<div style={{ display: 'flex', justifyContent: 'center', gap: 15 }}>
<Spin />
{lang === 'zh-CN' ? '跳转中...' : 'Redirecting...'}
<Spin spinning={loading} />
{text ? text : lang === 'zh-CN' ? '跳转中...' : 'Redirecting...'}
</div>
);
};
6 changes: 2 additions & 4 deletions .dumi/pages/guide.en-US.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* order: 2
*/

import { Redirect } from '../components/Redirect';
import Guide from './guide';

export default () => {
return <Redirect url="https://openspg.yuque.com/ndx6g9/ns5nw2" />;
};
export default Guide;
16 changes: 15 additions & 1 deletion .dumi/pages/guide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@
* order: 2
*/
import { Redirect } from '../components/Redirect';
import { Button, Typography, Flex } from 'antd';
import { useLocale } from 'dumi';

const { Title } = Typography;

export default () => {
return <Redirect url="https://openspg.yuque.com/ndx6g9/ooil9x" />;
const { id: locale } = useLocale();
const intl = (zh: string, en: string) => (locale === 'zh-CN' ? zh : en);

return <div>
<Title level={4}>{intl('版本', 'Version')}</Title>
<Redirect url={intl('https://openspg.yuque.com/ndx6g9/nmwkzz', 'https://openspg.yuque.com/ndx6g9/ps5q6b')} target='_blank' text=" " />
<Flex vertical align={'flex-start'}>
<Button type="link" target="_blank" href={intl('https://openspg.yuque.com/ndx6g9/ooil9x', 'https://openspg.yuque.com/ndx6g9/ns5nw2')}>0.0.2</Button>
<Button type="link" target="_blank" href={intl('https://openspg.yuque.com/ndx6g9/nmwkzz', 'https://openspg.yuque.com/ndx6g9/ps5q6b')}>0.0.3</Button>
</Flex>
</div>;
};

0 comments on commit 358b44a

Please sign in to comment.