import React, { useState, useLayoutEffect, useMemo } from 'react'; import { Typography, Space, Skeleton, Avatar } from 'antd'; import { useRouteMeta } from 'dumi'; import DayJS from 'dayjs'; import { CalendarOutlined } from '@ant-design/icons'; const AuthorAvatar: React.FC<{ name: string; avatar: string }> = ({ name, avatar }) => { const [loading, setLoading] = useState(true); const [error, setError] = useState(false); useLayoutEffect(() => { const img = new Image(); img.src = avatar; img.onload = () => setLoading(false); img.onerror = () => setError(true); }, []); if (error) { return null; } if (loading) { return ; } return ( {name} ); }; const DocMeta: React.FC<{}> = () => { const meta = useRouteMeta(); const mergedAuthorInfos = useMemo(() => { const { author } = meta.frontmatter; if (!author) { return []; } if (typeof author === 'string') { return author.split(',').map((item) => ({ name: item, avatar: `https://github.com/${item}.png`, })); } if (Array.isArray(author)) { return author; } return []; }, [meta.frontmatter.author]); if (!meta.frontmatter.date && !meta.frontmatter.author) { return null; } return ( {meta.frontmatter.date && ( {DayJS(meta.frontmatter.date).format('YYYY-MM-DD')} )} {mergedAuthorInfos.map((info) => ( @{info.name} ))} ); }; export default DocMeta;