Browse Source
* Pass route lists explicitly * Inline MarkdownPage into Page * Pass breadcrumbs from above * Remove state from router utils * Pass section from abovemain
dan
2 years ago
committed by
GitHub
14 changed files with 150 additions and 213 deletions
@ -1,58 +0,0 @@ |
|||
/* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
*/ |
|||
|
|||
import * as React from 'react'; |
|||
import {useRouter} from 'next/router'; |
|||
import {DocsPageFooter} from 'components/DocsFooter'; |
|||
import {Seo} from 'components/Seo'; |
|||
import PageHeading from 'components/PageHeading'; |
|||
import {useRouteMeta} from './useRouteMeta'; |
|||
import {useActiveSection} from '../../hooks/useActiveSection'; |
|||
import {TocContext} from '../MDX/TocContext'; |
|||
|
|||
import(/* webpackPrefetch: true */ '../MDX/CodeBlock/CodeBlock'); |
|||
|
|||
export interface MarkdownProps<Frontmatter> { |
|||
meta: Frontmatter & {description?: string}; |
|||
children?: React.ReactNode; |
|||
toc: Array<{ |
|||
url: string; |
|||
text: React.ReactNode; |
|||
depth: number; |
|||
}>; |
|||
} |
|||
|
|||
export function MarkdownPage< |
|||
T extends {title: string; status?: string} = {title: string; status?: string} |
|||
>({children, meta, toc}: MarkdownProps<T>) { |
|||
const {route, nextRoute, prevRoute} = useRouteMeta(); |
|||
const section = useActiveSection(); |
|||
const title = meta.title || route?.title || ''; |
|||
const description = meta.description || route?.description || ''; |
|||
const isHomePage = section === 'home'; |
|||
return ( |
|||
<> |
|||
<div className="pl-0"> |
|||
<Seo title={title} /> |
|||
{!isHomePage && ( |
|||
<PageHeading |
|||
title={title} |
|||
description={description} |
|||
tags={route?.tags} |
|||
/> |
|||
)} |
|||
<div className="px-5 sm:px-12"> |
|||
<div className="max-w-7xl mx-auto"> |
|||
<TocContext.Provider value={toc}>{children}</TocContext.Provider> |
|||
</div> |
|||
<DocsPageFooter |
|||
route={route} |
|||
nextRoute={nextRoute} |
|||
prevRoute={prevRoute} |
|||
/> |
|||
</div> |
|||
</div> |
|||
</> |
|||
); |
|||
} |
@ -1,16 +0,0 @@ |
|||
/* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
*/ |
|||
|
|||
import {useRouter} from 'next/router'; |
|||
|
|||
export function useActiveSection(): 'learn' | 'reference' | 'home' { |
|||
const {asPath} = useRouter(); |
|||
if (asPath.startsWith('/reference')) { |
|||
return 'reference'; |
|||
} else if (asPath.startsWith('/learn')) { |
|||
return 'learn'; |
|||
} else { |
|||
return 'home'; |
|||
} |
|||
} |
@ -1,16 +0,0 @@ |
|||
/* |
|||
* Copyright (c) Facebook, Inc. and its affiliates. |
|||
*/ |
|||
|
|||
import {useRouter} from 'next/router'; |
|||
|
|||
export function useActiveSection(): 'learn' | 'reference' | 'home' { |
|||
const {asPath} = useRouter(); |
|||
if (asPath.startsWith('/learn')) { |
|||
return 'learn'; |
|||
} else if (asPath.startsWith('/reference')) { |
|||
return 'reference'; |
|||
} else { |
|||
return 'home'; |
|||
} |
|||
} |
Loading…
Reference in new issue