From 953201717e6b0bf0bcec58b9f9397a6c2db0271b Mon Sep 17 00:00:00 2001 From: unix Date: Mon, 13 Apr 2020 19:23:15 +0800 Subject: [PATCH 1/3] docs: show contributors on document site --- lib/components/attributes/attributes.tsx | 64 +++++++++++--- lib/data/contributors.json | 1 + now.json | 3 + package.json | 9 +- scripts/collect-contributors.js | 101 +++++++++++++++++++++++ yarn.lock | 30 +++++++ 6 files changed, 194 insertions(+), 14 deletions(-) create mode 100644 lib/data/contributors.json create mode 100644 scripts/collect-contributors.js diff --git a/lib/components/attributes/attributes.tsx b/lib/components/attributes/attributes.tsx index d82f5fe..7e9d44a 100644 --- a/lib/components/attributes/attributes.tsx +++ b/lib/components/attributes/attributes.tsx @@ -1,20 +1,35 @@ import React, { useMemo } from 'react' -import { Card, Link, Spacer, useTheme } from 'components' +import { Card, Link, Spacer, Avatar, Tooltip, useTheme } from 'components' import AttributesTitle from './attributes-title' import VirtualAnchor from 'lib/components/anchor' import { useConfigs } from '../../config-context' +import ContributorMetadatas from 'lib/data/contributors.json' +const GithubURL = 'https://github.com/zeit-ui/react/blob/master' export interface AttributesProps { edit: string } +export interface Contributor { + name: string + avatar: string + url: string +} + +export type ContributorMeta = { + [key: string]: Array +} + const Attributes: React.FC> = React.memo(({ edit, children, }) => { const theme = useTheme() const { isChinese } = useConfigs() - const link = useMemo(() => { - return `https://github.com/zeit-ui/react/blob/master${edit || '/pages'}` + const link = useMemo(() => `${GithubURL}${edit || '/pages'}`, []) + const contributors = useMemo(() => { + const key = edit.replace('/pages', 'pages') + const users = (ContributorMetadatas as ContributorMeta)[key] + return users || [] }, []) return ( @@ -24,10 +39,22 @@ const Attributes: React.FC> = React.mem {children} - - - {isChinese ? '在 GitHub 上编辑此页面' : 'Edit this page on GitHub'} - + +

{isChinese ? '文档贡献者' : 'Contributors'}

+
+ {contributors.map((user, index) => ( + {user.name}} key={`${user.url}-${index}`}> + + + + + ))} + + + + + +