Browse Source

docs: Use cdn to speed up (#30973)

pull/30977/head
二货机器人 3 years ago
committed by GitHub
parent
commit
ce1aad03da
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      site/theme/template/Home/MorePage.tsx
  2. 2
      site/theme/template/Home/util.tsx
  3. 14
      site/theme/template/Resources/Articles/index.tsx

6
site/theme/template/Home/MorePage.tsx

@ -6,7 +6,7 @@ import './MorePage.less';
type SourceType = 'zhihu' | 'yuque'; type SourceType = 'zhihu' | 'yuque';
type Icons = Record<SourceType, string>; type Icons = { name: string; href: string }[];
interface MoreProps { interface MoreProps {
title: string; title: string;
@ -42,7 +42,9 @@ const MoreCard = ({ title, description, date, img, source, href, icons, loading
<div> <div>
{date} {date}
<span className="more-card-source"> <span className="more-card-source">
{icons ? <img src={icons[source]} alt={source} /> : null} {icons ? (
<img src={icons.find(icon => icon.name === source)?.href} alt={source} />
) : null}
</span> </span>
</div> </div>
</Card> </Card>

2
site/theme/template/Home/util.tsx

@ -22,7 +22,7 @@ export function useSiteData<T>(): [T, boolean] {
React.useEffect(() => { React.useEffect(() => {
if (Object.keys(data).length === 0 && typeof fetch !== 'undefined') { if (Object.keys(data).length === 0 && typeof fetch !== 'undefined') {
setLoading(true); setLoading(true);
fetch(`https://raw.githubusercontent.com/ant-design/website-data/main/db.json`) fetch(`https://render.alipay.com/p/h5data/antd4-config_website-h5data.json`)
.then(res => res.json()) .then(res => res.json())
.then(result => { .then(result => {
setData(result); setData(result);

14
site/theme/template/Resources/Articles/index.tsx

@ -26,9 +26,7 @@ interface Articles {
en: Article[]; en: Article[];
} }
interface Authors { type Authors = Author[];
[name: string]: Author;
}
interface ArticleListProps { interface ArticleListProps {
name: React.ReactNode; name: React.ReactNode;
@ -36,16 +34,16 @@ interface ArticleListProps {
authors: Authors; authors: Authors;
} }
const ArticleList: React.FC<ArticleListProps> = ({ name, data, authors = {} }) => ( const ArticleList: React.FC<ArticleListProps> = ({ name, data, authors = [] }) => (
<td> <td>
<h4>{name}</h4> <h4>{name}</h4>
<ul className="article-list"> <ul className="article-list">
{data.map((article, index) => { {data.map((article, index) => {
const author = authors[article.author] || {}; const author = authors.find(auth => auth.name === article.author);
return ( return (
<li key={index}> <li key={index}>
<a href={author.href} target="_blank" rel="noreferrer"> <a href={author?.href} target="_blank" rel="noreferrer">
<Avatar size="small" src={author.avatar} /> <Avatar size="small" src={author?.avatar} />
</a> </a>
<Divider type="vertical" /> <Divider type="vertical" />
<a href={article.href} target="_blank" rel="noreferrer"> <a href={article.href} target="_blank" rel="noreferrer">
@ -61,7 +59,7 @@ const ArticleList: React.FC<ArticleListProps> = ({ name, data, authors = {} }) =
export default () => { export default () => {
const { locale } = useIntl(); const { locale } = useIntl();
const isZhCN = locale === 'zh-CN'; const isZhCN = locale === 'zh-CN';
const [{ articles = { cn: [], en: [] }, authors = {} }, loading] = const [{ articles = { cn: [], en: [] }, authors = [] }, loading] =
useSiteData<{ articles: Articles; authors: Authors }>(); useSiteData<{ articles: Articles; authors: Authors }>();
// ========================== Data ========================== // ========================== Data ==========================

Loading…
Cancel
Save