-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
/
Copy pathindex.js
59 lines (51 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import {MDXProvider} from '@mdx-js/react';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
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 {matchPath} from '@docusaurus/router';
import styles from './styles.module.css';
function matchingRouteExist(routes, pathname) {
return routes.some(route => matchPath(pathname, route));
}
function DocPage(props) {
const {route, docsMetadata, location} = props;
const {permalinkToSidebar, docsSidebars} = docsMetadata;
const sidebar = permalinkToSidebar[location.pathname.replace(/\/$/, '')];
const {siteConfig: {themeConfig = {}} = {}} = useDocusaurusContext();
const {sidebarCollapsible = true} = themeConfig;
if (!matchingRouteExist(route.routes, location.pathname)) {
return <NotFound {...props} />;
}
return (
<Layout>
<div className={styles.docPage}>
{sidebar && (
<div className={styles.docSidebarContainer}>
<DocSidebar
docsSidebars={docsSidebars}
location={location}
sidebar={sidebar}
sidebarCollapsible={sidebarCollapsible}
/>
</div>
)}
<main className={styles.docMainContainer}>
<MDXProvider components={MDXComponents}>
{renderRoutes(route.routes)}
</MDXProvider>
</main>
</div>
</Layout>
);
}
export default DocPage;