From 1d2e0db8f4e4d6569d567059e3690007db36607b Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Tue, 25 Jul 2023 15:15:42 +0800 Subject: [PATCH] docs: fix resource page (#43782) * docs: fix resource page * chore: fix min-height * chore: add test --- .../theme/builtins/ResourceArticles/index.tsx | 80 +++++++++---------- .dumi/theme/layouts/DocLayout/index.tsx | 2 +- .dumi/theme/layouts/ResourceLayout/index.tsx | 1 + scripts/check-site.ts | 12 +++ 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/.dumi/theme/builtins/ResourceArticles/index.tsx b/.dumi/theme/builtins/ResourceArticles/index.tsx index 5debaa98dd..ccf34340eb 100644 --- a/.dumi/theme/builtins/ResourceArticles/index.tsx +++ b/.dumi/theme/builtins/ResourceArticles/index.tsx @@ -1,11 +1,13 @@ /* eslint-disable react/no-array-index-key */ import * as React from 'react'; +import { Suspense } from 'react'; import dayjs from 'dayjs'; -import { FormattedMessage, useIntl } from 'dumi'; +import { FormattedMessage } from 'dumi'; import { Avatar, Divider, Empty, Skeleton, Tabs } from 'antd'; import { createStyles } from 'antd-style'; import type { Article, Authors } from '../../../pages/index/components/util'; import { useSiteData } from '../../../pages/index/components/util'; +import useLocale from '../../../hooks/useLocale'; const useStyle = createStyles(({ token, css }) => { const { antCls } = token; @@ -93,17 +95,15 @@ const ArticleList: React.FC = ({ name, data = [], authors = [] ); }; -export default () => { - const { locale } = useIntl(); - const isZhCN = locale === 'zh-CN'; - const [{ articles = { cn: [], en: [] }, authors = [] }, loading] = useSiteData(); - - const { styles } = useStyle(); +const Articles = () => { + const [, lang] = useLocale(); + const isZhCN = lang === 'cn'; + const { articles = { cn: [], en: [] }, authors = [] } = useSiteData(); // ========================== Data ========================== const mergedData = React.useMemo(() => { const yearData: Record> = {}; - articles[isZhCN ? 'cn' : 'en']?.forEach((article) => { + articles[lang]?.forEach((article) => { const year = dayjs(article.date).year(); yearData[year] = yearData[year] || {}; yearData[year][article.type] = [...(yearData[year][article.type] || []), article]; @@ -111,42 +111,42 @@ export default () => { return yearData; }, [articles]); - // ========================= Render ========================= - let content: React.ReactNode; + const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a)); - if (loading) { - content = ; - } else { - const yearList = Object.keys(mergedData).sort((a, b) => Number(b) - Number(a)); - content = yearList.length ? ( - - {yearList.map((year) => ( - - - - - } - data={mergedData[year].design} - authors={authors} - /> - } - data={mergedData[year].develop} - authors={authors} - /> - - -
-
- ))} -
- ) : null; - } + return yearList.length ? ( + + {yearList.map((year) => ( + + + + + } + data={mergedData[year].design} + authors={authors} + /> + } + data={mergedData[year].develop} + authors={authors} + /> + + +
+
+ ))} +
+ ) : null; +}; + +export default () => { + const { styles } = useStyle(); return (
- {content} + }> + +
); }; diff --git a/.dumi/theme/layouts/DocLayout/index.tsx b/.dumi/theme/layouts/DocLayout/index.tsx index 608ec21b63..20cfd277e8 100644 --- a/.dumi/theme/layouts/DocLayout/index.tsx +++ b/.dumi/theme/layouts/DocLayout/index.tsx @@ -76,7 +76,7 @@ const DocLayout: React.FC = () => { ) { return ( <> - {outlet} +
{outlet}