/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React, {useState, useEffect, useCallback} from 'react'; import {MDXProvider} from '@mdx-js/react'; import renderRoutes from '@docusaurus/renderRoutes'; import Layout from '@theme/Layout'; import DocSidebar from '@theme/DocSidebar'; import MDXComponents from '@theme/MDXComponents'; import NotFound from '@theme/NotFound'; import IconArrow from '@theme/IconArrow'; import BackToTopButton from '@theme/BackToTopButton'; import {matchPath} from '@docusaurus/router'; import {translate} from '@docusaurus/Translate'; import clsx from 'clsx'; import styles from './styles.module.css'; import { ThemeClassNames, docVersionSearchTag, DocsSidebarProvider, useDocsSidebar, DocsVersionProvider, } from '@docusaurus/theme-common'; import Head from '@docusaurus/Head'; import amplitude from 'amplitude-js'; function DocPageContent({ currentDocRoute, versionMetadata, children, sidebarName, }) { const sidebar = useDocsSidebar(); const {pluginId, version} = versionMetadata; const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false); const [hiddenSidebar, setHiddenSidebar] = useState(false); const toggleSidebar = useCallback(() => { if (hiddenSidebar) { setHiddenSidebar(false); } setHiddenSidebarContainer((value) => !value); }, [hiddenSidebar]); return (
{sidebar && ( )}
{children}
); } function DocPage(props) { const { route: {routes: docRoutes}, versionMetadata, location, } = props; const currentDocRoute = docRoutes.find((docRoute) => matchPath(location.pathname, docRoute), ); // DocPage Swizzle useEffect(() => { amplitude.getInstance().logEvent('Docs Viewed', { "hostname": window.location.hostname, "path": location.pathname }); }, [location.pathname]) // End DocPageSwizzle if (!currentDocRoute) { return ; } // For now, the sidebarName is added as route config: not ideal! const sidebarName = currentDocRoute.sidebar; const sidebar = sidebarName ? versionMetadata.docsSidebars[sidebarName] : null; return ( <> {/* TODO we should add a core addRoute({htmlClassName}) generic plugin option */}
{renderRoutes(docRoutes, { versionMetadata, })}
); } export default DocPage;