mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-11 23:32:30 +02:00
fix(v2): bootstrap doc sidebar (#2860)
* fix(v2): doc sidebar * chore(v2): prettier * fix(v2): docs navbar path * fix(v2): fix error about activepath * chore(v2): prettier * feat(v2): change active color * feat(v2): update to new docs cpmfog * feat(v2): Add homepagepath
This commit is contained in:
parent
174cd8dc6f
commit
8a34872750
3 changed files with 81 additions and 11 deletions
31
packages/docusaurus-theme-bootstrap/README.md
Normal file
31
packages/docusaurus-theme-bootstrap/README.md
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Docusaurus Theme Bootstrap
|
||||||
|
|
||||||
|
The bootstrap theme for Docusaurus.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Add `docusaurus/theme-bootstrap` to your package:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm i @docusaurus/theme-bootstrao
|
||||||
|
# or
|
||||||
|
yarn add @docusaurus/theme-bootstrap
|
||||||
|
```
|
||||||
|
|
||||||
|
Modify your `docusaurus.config.js`:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
module.exports = {
|
||||||
|
...
|
||||||
|
+ themes: ['@docusaurus/theme-bootstrap'],
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Swizzling components
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ npm swizzle @docusaurus/theme-bootstrap [component name]
|
||||||
|
```
|
||||||
|
|
||||||
|
All components used by this theme can be found [here](https://github.com/facebook/docusaurus/tree/master/packages/docusaurus-theme-bootstrap/src/theme)
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import renderRoutes from '@docusaurus/renderRoutes';
|
import renderRoutes from '@docusaurus/renderRoutes';
|
||||||
|
import NotFound from '@theme/NotFound';
|
||||||
|
import DocItem from '@theme/DocItem';
|
||||||
import DocSidebar from '@theme/DocSidebar';
|
import DocSidebar from '@theme/DocSidebar';
|
||||||
import MDXComponents from '@theme/MDXComponents';
|
import MDXComponents from '@theme/MDXComponents';
|
||||||
import Layout from '@theme/Layout';
|
import Layout from '@theme/Layout';
|
||||||
|
@ -14,25 +16,41 @@ import {MDXProvider} from '@mdx-js/react';
|
||||||
import {matchPath} from '@docusaurus/router';
|
import {matchPath} from '@docusaurus/router';
|
||||||
|
|
||||||
function DocPage(props) {
|
function DocPage(props) {
|
||||||
const {route: baseRoute, docsMetadata, location} = props;
|
const {route: baseRoute, docsMetadata, location, content} = props;
|
||||||
|
const {
|
||||||
|
permalinkToSidebar,
|
||||||
|
docsSidebars,
|
||||||
|
isHomePage,
|
||||||
|
homePagePath,
|
||||||
|
} = docsMetadata;
|
||||||
// case-sensitive route such as it is defined in the sidebar
|
// case-sensitive route such as it is defined in the sidebar
|
||||||
const currentRoute =
|
const currentRoute = !isHomePage
|
||||||
baseRoute.routes.find((route) => {
|
? baseRoute.routes.find((route) => {
|
||||||
return matchPath(location.pathname, route);
|
return matchPath(location.pathname, route);
|
||||||
}) || {};
|
}) || {}
|
||||||
const {permalinkToSidebar, docsSidebars} = docsMetadata;
|
: {};
|
||||||
const sidebar = permalinkToSidebar[currentRoute.path];
|
const sidebar = isHomePage
|
||||||
|
? content.metadata.sidebar
|
||||||
|
: permalinkToSidebar[currentRoute.path];
|
||||||
|
|
||||||
|
if (!isHomePage && Object.keys(currentRoute).length === 0) {
|
||||||
|
return <NotFound {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout title="Doc page" description="My Doc page">
|
<Layout title="Doc page" description="My Doc page">
|
||||||
<DocSidebar
|
<DocSidebar
|
||||||
docsSidebars={docsSidebars}
|
docsSidebars={docsSidebars}
|
||||||
path={currentRoute.path}
|
path={isHomePage ? homePagePath : currentRoute.path}
|
||||||
sidebar={sidebar}
|
sidebar={sidebar}
|
||||||
/>
|
/>
|
||||||
<section className="offset-1 mr-4 mt-4 col-xl-6 offset-xl-4 p-0 justify-content-center align-self-center overflow-hidden">
|
<section className="offset-1 mr-4 mt-4 col-xl-6 offset-xl-4 p-0 justify-content-center align-self-center overflow-hidden">
|
||||||
<MDXProvider components={MDXComponents}>
|
<MDXProvider components={MDXComponents}>
|
||||||
{renderRoutes(baseRoute.routes)}
|
{isHomePage ? (
|
||||||
|
<DocItem content={content} />
|
||||||
|
) : (
|
||||||
|
renderRoutes(baseRoute.routes)
|
||||||
|
)}
|
||||||
</MDXProvider>
|
</MDXProvider>
|
||||||
</section>
|
</section>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -18,8 +18,19 @@ import {
|
||||||
NavItem as NavItemBase,
|
NavItem as NavItemBase,
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
|
|
||||||
function NavItem({href, label, to, ...props}) {
|
function NavItem({
|
||||||
|
activeBasePath,
|
||||||
|
activeBaseRegex,
|
||||||
|
href,
|
||||||
|
label,
|
||||||
|
to,
|
||||||
|
activeClassName = 'nav-link text-info',
|
||||||
|
prependBaseUrlToHref,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
const toUrl = useBaseUrl(to);
|
const toUrl = useBaseUrl(to);
|
||||||
|
const activeBaseUrl = useBaseUrl(activeBasePath);
|
||||||
|
const normalizedHref = useBaseUrl(href, true);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavItemBase>
|
<NavItemBase>
|
||||||
|
@ -29,10 +40,20 @@ function NavItem({href, label, to, ...props}) {
|
||||||
? {
|
? {
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
rel: 'noopener noreferrer',
|
rel: 'noopener noreferrer',
|
||||||
href,
|
href: prependBaseUrlToHref ? normalizedHref : href,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
|
isNavLink: true,
|
||||||
|
activeClassName,
|
||||||
to: toUrl,
|
to: toUrl,
|
||||||
|
...(activeBasePath || activeBaseRegex
|
||||||
|
? {
|
||||||
|
isActive: (_match, location) =>
|
||||||
|
activeBaseRegex
|
||||||
|
? new RegExp(activeBaseRegex).test(location.pathname)
|
||||||
|
: location.pathname.startsWith(activeBaseUrl),
|
||||||
|
}
|
||||||
|
: null),
|
||||||
})}
|
})}
|
||||||
{...props}>
|
{...props}>
|
||||||
{label}
|
{label}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue