Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat: header 增加下拉菜单,可以存放一些生态的外链 #317

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions @antv/gatsby-theme-antv/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ exports.sourceNodes = ({ actions }) => {
en: String
}

type SiteSiteMetadataEcosystemName {
zh: String
en: String
}

type SiteSiteMetadataDocs {
slug: String!
title: SiteSiteMetadataTitle!
Expand All @@ -487,6 +492,11 @@ exports.sourceNodes = ({ actions }) => {
to: String
}

type Ecosystems {
name: SiteSiteMetadataEcosystemName!
url: String!
}

type SiteSiteMetadata {
title: String!
description: String!
Expand All @@ -511,6 +521,7 @@ exports.sourceNodes = ({ actions }) => {
playground: PlayGround
docsearchOptions: DocsearchOptions
versions: Json
ecosystems: [Ecosystems]
}

type Site implements Node {
Expand Down
31 changes: 31 additions & 0 deletions @antv/gatsby-theme-antv/site/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
GithubOutlined,
MenuOutlined,
CaretDownFilled,
DownOutlined,
} from '@ant-design/icons';
import { Popover, Button, Menu, Select, Dropdown, message, Modal } from 'antd';
import GitUrlParse from 'git-url-parse';
import map from 'lodash/map';
import Search, { SearchProps } from './Search';
import Products from './Products';
import NavMenuItems, { Nav } from './NavMenuItems';
Expand Down Expand Up @@ -70,6 +72,11 @@ interface HeaderProps {
docsearchOptions?: SearchProps['docsearchOptions'];
/** 展示版本切换 */
versions?: { [key: string]: string };
/** 展示周边生态 */
ecosystems?: Array<{
name: Record<string /** zh, en */, string>;
url: string;
}>;
}

export const redirectToChinaMirror = (githubUrl: string): void => {
Expand Down Expand Up @@ -124,6 +131,7 @@ const Header: React.FC<HeaderProps> = ({
rootDomain = '',
docsearchOptions,
versions,
ecosystems,
}) => {
const { t, i18n } = useTranslation();
const isAntVHome = isAntVSite && isHomePage; // 是否为AntV官网首页
Expand Down Expand Up @@ -243,6 +251,28 @@ const Header: React.FC<HeaderProps> = ({
})}
>
{navs && navs.length ? <NavMenuItems navs={navs} path={path} /> : null}
{ecosystems && ecosystems.length ? (
<li>
<Dropdown
overlay={
<Menu>
{map(ecosystems, ({ url, name: ecosystemName }) => (
<Menu.Item key={ecosystemName?.[lang]}>
<a target="_blank" rel="noreferrer" href={url}>
visiky marked this conversation as resolved.
Show resolved Hide resolved
{ecosystemName?.[lang]} <ExternalLinkIcon />
</a>
</Menu.Item>
))}
</Menu>
}
>
<span>
{t('周边生态')}
<DownOutlined style={{ marginLeft: '6px' }} />
</span>
</Dropdown>
</li>
) : null}
{showChinaMirror && isWide ? (
<Popover
title={null}
Expand Down Expand Up @@ -398,6 +428,7 @@ const Header: React.FC<HeaderProps> = ({
</Select>
</li>
) : null}

{showLanguageSwitcher && (
<li>
<Dropdown
Expand Down
9 changes: 9 additions & 0 deletions @antv/gatsby-theme-antv/site/layouts/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ const Layout: React.FC<LayoutProps> = ({ children, location, footerProps }) => {
indexName
}
versions
ecosystems {
name {
zh
en
}
url
}
}
}
locales {
Expand All @@ -100,6 +107,7 @@ const Layout: React.FC<LayoutProps> = ({ children, location, footerProps }) => {
redirects = [],
docsearchOptions,
versions,
ecosystems,
},
} = site;

Expand Down Expand Up @@ -204,6 +212,7 @@ const Layout: React.FC<LayoutProps> = ({ children, location, footerProps }) => {
showLanguageSwitcher={parseNulltoUndefined(showLanguageSwitcher)}
docsearchOptions={docsearchOptions}
versions={versions}
ecosystems={ecosystems}
{...logoProps}
/>
<main className={styles.main}>{children}</main>
Expand Down
16 changes: 16 additions & 0 deletions example/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ module.exports = {
'2.x': 'https://2x.ant.design',
'1.x': 'https://1x.ant.design',
},
ecosystems: [
{
name: {
zh: '蚂蚁设计',
en: 'Ant Design',
},
url: 'https://2x.ant.design',
},
{
name: {
zh: '图表加工厂',
en: 'ChartCube',
},
url: 'https://chartcube.alipay.com/',
},
],
playground: {
container: '<div id="container" class="ok" />',
playgroundDidMount: 'console.log("playgroundDidMount");',
Expand Down