mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
docs: fix resource page (#43782)
* docs: fix resource page * chore: fix min-height * chore: add test
This commit is contained in:
parent
cba1493a83
commit
1d2e0db8f4
@ -1,11 +1,13 @@
|
|||||||
/* eslint-disable react/no-array-index-key */
|
/* eslint-disable react/no-array-index-key */
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { Suspense } from 'react';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { FormattedMessage, useIntl } from 'dumi';
|
import { FormattedMessage } from 'dumi';
|
||||||
import { Avatar, Divider, Empty, Skeleton, Tabs } from 'antd';
|
import { Avatar, Divider, Empty, Skeleton, Tabs } from 'antd';
|
||||||
import { createStyles } from 'antd-style';
|
import { createStyles } from 'antd-style';
|
||||||
import type { Article, Authors } from '../../../pages/index/components/util';
|
import type { Article, Authors } from '../../../pages/index/components/util';
|
||||||
import { useSiteData } from '../../../pages/index/components/util';
|
import { useSiteData } from '../../../pages/index/components/util';
|
||||||
|
import useLocale from '../../../hooks/useLocale';
|
||||||
|
|
||||||
const useStyle = createStyles(({ token, css }) => {
|
const useStyle = createStyles(({ token, css }) => {
|
||||||
const { antCls } = token;
|
const { antCls } = token;
|
||||||
@ -93,17 +95,15 @@ const ArticleList: React.FC<ArticleListProps> = ({ name, data = [], authors = []
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default () => {
|
const Articles = () => {
|
||||||
const { locale } = useIntl();
|
const [, lang] = useLocale();
|
||||||
const isZhCN = locale === 'zh-CN';
|
const isZhCN = lang === 'cn';
|
||||||
const [{ articles = { cn: [], en: [] }, authors = [] }, loading] = useSiteData();
|
const { articles = { cn: [], en: [] }, authors = [] } = useSiteData();
|
||||||
|
|
||||||
const { styles } = useStyle();
|
|
||||||
|
|
||||||
// ========================== Data ==========================
|
// ========================== Data ==========================
|
||||||
const mergedData = React.useMemo(() => {
|
const mergedData = React.useMemo(() => {
|
||||||
const yearData: Record<number | string, Record<string, Article[]>> = {};
|
const yearData: Record<number | string, Record<string, Article[]>> = {};
|
||||||
articles[isZhCN ? 'cn' : 'en']?.forEach((article) => {
|
articles[lang]?.forEach((article) => {
|
||||||
const year = dayjs(article.date).year();
|
const year = dayjs(article.date).year();
|
||||||
yearData[year] = yearData[year] || {};
|
yearData[year] = yearData[year] || {};
|
||||||
yearData[year][article.type] = [...(yearData[year][article.type] || []), article];
|
yearData[year][article.type] = [...(yearData[year][article.type] || []), article];
|
||||||
@ -111,14 +111,9 @@ export default () => {
|
|||||||
return yearData;
|
return yearData;
|
||||||
}, [articles]);
|
}, [articles]);
|
||||||
|
|
||||||
// ========================= Render =========================
|
|
||||||
let content: React.ReactNode;
|
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
content = <Skeleton active />;
|
|
||||||
} else {
|
|
||||||
const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a));
|
const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a));
|
||||||
content = yearList.length ? (
|
|
||||||
|
return yearList.length ? (
|
||||||
<Tabs>
|
<Tabs>
|
||||||
{yearList.map((year) => (
|
{yearList.map((year) => (
|
||||||
<Tabs.TabPane tab={`${year}${isZhCN ? ' 年' : ''}`} key={year}>
|
<Tabs.TabPane tab={`${year}${isZhCN ? ' 年' : ''}`} key={year}>
|
||||||
@ -142,11 +137,16 @@ export default () => {
|
|||||||
))}
|
))}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
) : null;
|
) : null;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const { styles } = useStyle();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="articles" className={styles.articles}>
|
<div id="articles" className={styles.articles}>
|
||||||
{content}
|
<Suspense fallback={<Skeleton active />}>
|
||||||
|
<Articles />
|
||||||
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -76,7 +76,7 @@ const DocLayout: React.FC = () => {
|
|||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{outlet}
|
<div style={{ minHeight: '100vh' }}>{outlet}</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -34,6 +34,7 @@ const useStyle = createStyles(({ token, css }) => {
|
|||||||
max-width: ${articleMaxWidth}px;
|
max-width: ${articleMaxWidth}px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
|
min-height: 100vh;
|
||||||
|
|
||||||
> .markdown {
|
> .markdown {
|
||||||
> p {
|
> p {
|
||||||
|
@ -75,6 +75,18 @@ describe('site test', () => {
|
|||||||
expect($('h1').text()).toMatch(`组件总览`);
|
expect($('h1').text()).toMatch(`组件总览`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Resource en', async () => {
|
||||||
|
const { status, $ } = await render('/docs/resources');
|
||||||
|
expect(status).toBe(200);
|
||||||
|
expect($('h1').text()).toMatch(`Resources`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Resource zh', async () => {
|
||||||
|
const { status, $ } = await render('/docs/resources-cn');
|
||||||
|
expect(status).toBe(200);
|
||||||
|
expect($('h1').text()).toMatch(`资源`);
|
||||||
|
});
|
||||||
|
|
||||||
for (const component of components) {
|
for (const component of components) {
|
||||||
if (component.split('/').length < 3) {
|
if (component.split('/').length < 3) {
|
||||||
it(`Component ${component} zh Page`, async () => {
|
it(`Component ${component} zh Page`, async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user