From 2d67c0f0e4769bdc1722b1912c3d206944ab8e40 Mon Sep 17 00:00:00 2001 From: MadCcc Date: Mon, 4 Dec 2023 15:12:49 +0800 Subject: [PATCH] docs: site date client only (#46230) * docs: site date client only * chore: fix style * chore: fix lint --------- Co-authored-by: lijianan <574980606@qq.com> --- .../pages/index/components/BannerRecommends.tsx | 10 ++++++++-- .../index/components/PreviewBanner/index.tsx | 1 + .dumi/pages/index/components/Theme/index.tsx | 4 ++-- .dumi/pages/index/components/util.ts | 17 ++++++++++++++--- .dumi/pages/index/index.tsx | 6 ++---- .dumi/theme/builtins/ResourceArticles/index.tsx | 16 +++++++++------- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/.dumi/pages/index/components/BannerRecommends.tsx b/.dumi/pages/index/components/BannerRecommends.tsx index 0b9b7664bd..961f7576e7 100644 --- a/.dumi/pages/index/components/BannerRecommends.tsx +++ b/.dumi/pages/index/components/BannerRecommends.tsx @@ -115,7 +115,7 @@ export const BannerRecommendsFallback: FC = () => { return isMobile ? ( {list.map((_, index) => ( -
+
))} @@ -123,7 +123,9 @@ export const BannerRecommendsFallback: FC = () => { ) : (
{list.map((_, index) => ( - +
+ +
))}
); @@ -138,6 +140,10 @@ const BannerRecommends: React.FC = () => { const icons = data?.icons || []; const first3 = !extras || extras.length === 0 ? Array(3).fill(null) : extras.slice(0, 3); + if (!data) { + return ; + } + return (
{isMobile ? ( diff --git a/.dumi/pages/index/components/PreviewBanner/index.tsx b/.dumi/pages/index/components/PreviewBanner/index.tsx index ade9ea4188..cb26d82c1c 100644 --- a/.dumi/pages/index/components/PreviewBanner/index.tsx +++ b/.dumi/pages/index/components/PreviewBanner/index.tsx @@ -94,6 +94,7 @@ const useStyle = () => { child: css` position: relative; + width: 100%; z-index: 1; `, }; diff --git a/.dumi/pages/index/components/Theme/index.tsx b/.dumi/pages/index/components/Theme/index.tsx index 12e479e90f..399b377b34 100644 --- a/.dumi/pages/index/components/Theme/index.tsx +++ b/.dumi/pages/index/components/Theme/index.tsx @@ -407,8 +407,8 @@ export default function Theme() { components: { Layout: isLight ? { - colorBgHeader: 'transparent', - colorBgBody: 'transparent', + headerBg: 'transparent', + bodyBg: 'transparent', } : { // colorBgBody: 'transparent', diff --git a/.dumi/pages/index/components/util.ts b/.dumi/pages/index/components/util.ts index 295ff4bee7..a4cacaf55d 100644 --- a/.dumi/pages/index/components/util.ts +++ b/.dumi/pages/index/components/util.ts @@ -1,5 +1,6 @@ import { css } from 'antd-style'; -import useFetch from '../../../hooks/useFetch'; +import { useEffect, useState } from 'react'; +import fetch from 'cross-fetch'; export interface Author { avatar: string; @@ -80,8 +81,18 @@ export function preLoad(list: string[]) { } } -export function useSiteData(): Partial { - return useFetch('https://render.alipay.com/p/h5data/antd4-config_website-h5data.json'); +export function useSiteData(): Partial | undefined { + const [data, setData] = useState(undefined); + + useEffect(() => { + fetch('https://render.alipay.com/p/h5data/antd4-config_website-h5data.json').then( + async (res) => { + setData(await res.json()); + }, + ); + }, []); + + return data; } export const getCarouselStyle = () => ({ diff --git a/.dumi/pages/index/index.tsx b/.dumi/pages/index/index.tsx index 8e278e75d2..a528f4347e 100644 --- a/.dumi/pages/index/index.tsx +++ b/.dumi/pages/index/index.tsx @@ -4,7 +4,7 @@ import { createStyles, css } from 'antd-style'; import useDark from '../../hooks/useDark'; import useLocale from '../../hooks/useLocale'; -import BannerRecommends, { BannerRecommendsFallback } from './components/BannerRecommends'; +import BannerRecommends from './components/BannerRecommends'; import PreviewBanner from './components/PreviewBanner'; import Group from './components/Group'; @@ -46,9 +46,7 @@ const Homepage: React.FC = () => { return (
- }> - - +
diff --git a/.dumi/theme/builtins/ResourceArticles/index.tsx b/.dumi/theme/builtins/ResourceArticles/index.tsx index b6fbf635e9..d6bf4927f4 100644 --- a/.dumi/theme/builtins/ResourceArticles/index.tsx +++ b/.dumi/theme/builtins/ResourceArticles/index.tsx @@ -1,11 +1,10 @@ /* eslint-disable react/no-array-index-key */ import * as React from 'react'; -import { Suspense } from 'react'; import dayjs from 'dayjs'; import { FormattedMessage } from 'dumi'; import { createStyles } from 'antd-style'; import { Avatar, Divider, Empty, Skeleton, Tabs } from 'antd'; -import type { Article, Authors } from '../../../pages/index/components/util'; +import type { Article, Authors, SiteData } from '../../../pages/index/components/util'; import { useSiteData } from '../../../pages/index/components/util'; import useLocale from '../../../hooks/useLocale'; @@ -97,10 +96,11 @@ const ArticleList: React.FC = ({ name, data = [], authors = [] ); }; -const Articles: React.FC = () => { +const Articles: React.FC<{ data: Partial }> = ({ data }) => { const [, lang] = useLocale(); const isZhCN = lang === 'cn'; - const { articles = { cn: [], en: [] }, authors = [] } = useSiteData(); + + const { articles = { cn: [], en: [] }, authors = [] } = data; // ========================== Data ========================== const mergedData = React.useMemo(() => { @@ -149,11 +149,13 @@ const Articles: React.FC = () => { export default () => { const { styles } = useStyle(); + const data = useSiteData(); + + const articles = data ? : ; + return (
- }> - - + {articles}
); };