import React, { useState, useEffect, useContext } from 'react'; import { withPrefix } from 'gatsby'; import { default as RCFooter, FooterProps as RcFooterProps } from 'rc-footer'; import { useTranslation } from 'react-i18next'; import classnames from 'classnames'; import omit from 'omit.js'; import { LayoutContext } from '../layouts/layout-context'; import * as styles from './Footer.module.less'; import 'rc-footer/assets/index.less'; interface FooterProps extends RcFooterProps { rootDomain?: string; language?: string; githubUrl?: string; location: Location; } const Footer: React.FC = ({ columns, bottom, theme = 'dark', language, rootDomain = '', location, ...restProps }) => { const [withMenu, setWithMenu] = useState(false); const { t } = useTranslation(); const { collapsed } = useContext(LayoutContext); useEffect(() => { // 有 menu 的模版 footer 表现不同,通过 location 判断加载的模版 const pathPrefix = withPrefix('/').replace(/\/$/, ''); const path = location.pathname.replace(pathPrefix, ''); const isExamplePage = path.startsWith(`/zh/examples`) || path.startsWith(`/en/examples`); const isDocsPage = path.startsWith(`/zh/docs`) || path.startsWith(`/en/docs`); // examples 页面里目前只有 gallery 是有 footer 的, // 且 gallery 会出现 `location.key = 'initial'` 逻辑,所以先统一处理为需要 menu if (isExamplePage) { setWithMenu(true); } else if (isDocsPage) { // 文档页为 404 时 footer 没有 menu setWithMenu(!((location as any).key === 'initial')); } else { setWithMenu(false); } }, [location]); const getColums = () => { // 如果外部没有传入 columns,则默认展示默认 footer const col1 = { title: t('资源'), items: [ { icon: ( {t('WebIDE ), title: t('WebIDE 案例'), url: 'https://github.com/opensumi/ide-startup', openExternal: true, }, { icon: ( {t('Electron ), title: t('Electron 案例'), url: 'https://github.com/opensumi/ide-electron', openExternal: true, }, { icon: ( {t('纯前端案例')} ), title: t('纯前端案例'), url: 'https://github.com/opensumi/ide-startup-lite', openExternal: true, }, { icon: ( {t('官方主题')} ), title: t('官方主题'), url: 'https://github.com/opensumi/Default-Themes', openExternal: true, }, ], }; const col2 = { title: t('社区'), items: [ { icon: ( d2conf ), title: `D2 - ${t('D2 前端技术论坛')}`, url: 'https://d2.alibabatech.com/', openExternal: true, }, { icon: ( seeconf ), title: `SEE Conf - ${t('蚂蚁体验科技大会')}`, url: 'https://seeconf.antfin.com/', openExternal: true, }, ], }; const col3 = { title: t('帮助'), items: [ { icon: ( github ), title: 'GitHub Issues', url: 'https://github.com/opensumi/core/issues', openExternal: true, }, ], }; const more = { icon: ( more products ), title: t('更多产品'), items: [ { icon: ( {t('淘宝开发者工具')} ), title: t('淘宝开发者工具'), url: 'https://miniapp-dev.taobao.com/', openExternal: true, }, { icon: ( {t('支付宝小程序开发工具')} ), title: t('支付宝小程序开发工具'), url: 'https://opendocs.alipay.com/mini/ide/overview', openExternal: true, }, { icon: ( {t('支付宝小程序云 ), title: t('支付宝小程序云 Cloud IDE'), url: 'https://ide.cloud.alipay.com', openExternal: true, }, ], }; return [col1, col2, col3, more]; }; return ( ); }; export default Footer;