import React, { useContext, useState } from 'react'; import { IRouteComponentProps } from '@umijs/types'; import { context, Link } from 'dumi/theme'; import Navbar from 'dumi-theme-default/src/components/Navbar'; import SideMenu from 'dumi-theme-default/src/components/SideMenu'; import SlugList from 'dumi-theme-default/src/components/SlugList'; import SearchBar from 'dumi-theme-default/src/components/SearchBar'; import { Popover } from 'antd'; import { Helmet } from 'dumi' import Notice from './Notice'; import { useLocation } from 'react-router-dom' import './style/layout.less'; const Hero = hero => ( <>
{hero.image && }

{hero.title}

{hero.actions && hero.actions.map(action => ( ))}
); const WaimaiBanner = () => (

天天有点券

} trigger="hover" >
); const Features = features => (
{features.map(feat => (
{feat.link ? (
{feat.title}
) : (
{feat.title}
)}
))}
); const Layout: React.FC = ({ children, location }) => { const { config, meta, locale, } = useContext(context); const { mode, repository, logo, title } = config const { pathname } = useLocation(); // todo 临时方案 const hostname = 'https://brew.idayer.com' const { url: repoUrl, branch, platform } = repository; const [menuCollapsed, setMenuCollapsed] = useState(true); const isSiteMode = mode === 'site'; const showHero = isSiteMode && meta.hero; const showFeatures = isSiteMode && meta.features; const showSideMenu = meta.sidemenu !== false && !showHero && !showFeatures && !meta.gapless; const showSlugs = !showHero && !showFeatures && Boolean(meta.slugs?.length) && (meta.toc === 'content' || meta.toc === undefined) && !meta.gapless; const isCN = /^zh|cn$/i.test(locale); const updatedTime: any = new Date(meta.updatedTime).toLocaleString([], { hour12: false, }); const repoPlatform = { github: 'GitHub', gitlab: 'GitLab' }[ (repoUrl || '').match(/(github|gitlab)/)?.[1] || 'nothing' ] || platform; if(!meta.img && logo) { meta.img = logo } if(meta.img.indexOf('https://') === -1) { meta.img = hostname + meta.img } return (
{ if (menuCollapsed) return; setMenuCollapsed(true); }} > {meta.title && {meta.title + ' - ' + title}} {meta.title && } {meta.description && } {meta.description && ( )} {meta.keywords && ( )} {meta.keywords && meta.keywords.map((keyword) => ( ))} {/* */} {hostname && } {meta.img && ( )}
} onMobileMenuClick={ev => { setMenuCollapsed(val => !val); ev.stopPropagation(); }} /> {showSlugs && ( )} {showHero && Hero(meta.hero)} {showFeatures && Features(meta.features)}
{children} {!showHero && !showFeatures && meta.filePath && !meta.gapless && ( <>
{repoPlatform && ( {isCN ? `在 ${repoPlatform} 上编辑此页` : `Edit this doc on ${repoPlatform}`} )} {updatedTime}
{/**/} )} {(showHero || showFeatures) && meta.footer && (
)}
{!showHero && !showFeatures && meta.filePath && !meta.gapless && ( )}
); }; export default Layout;