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 Icons = Record<SourceType, string>;
type Icons = { name: string; href: string }[];
interface MoreProps {
title: string;
@ -42,7 +42,9 @@ const MoreCard = ({ title, description, date, img, source, href, icons, loading
<div>
{date}
<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>
</div>
</Card>

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

@ -22,7 +22,7 @@ export function useSiteData<T>(): [T, boolean] {
React.useEffect(() => {
if (Object.keys(data).length === 0 && typeof fetch !== 'undefined') {
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(result => {
setData(result);

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

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

Loading…
Cancel
Save