Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): bootstrap doc sidebar #2860

Merged
merged 8 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
},
links: [
{
to: 'docs/',
to: 'docs/doc1',
fanny marked this conversation as resolved.
Show resolved Hide resolved
activeBasePath: 'docs',
label: 'Docs',
position: 'left',
Expand Down
31 changes: 31 additions & 0 deletions packages/docusaurus-theme-bootstrap/README.md
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 10 additions & 6 deletions packages/docusaurus-theme-bootstrap/src/theme/DocPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ import {MDXProvider} from '@mdx-js/react';
import {matchPath} from '@docusaurus/router';

function DocPage(props) {
const {route: baseRoute, docsMetadata, location} = props;
const {route: baseRoute, docsMetadata, location, content} = props;
const {isHomePage} = docsMetadata;
// case-sensitive route such as it is defined in the sidebar
const currentRoute =
baseRoute.routes.find((route) => {
return matchPath(location.pathname, route);
}) || {};
const currentRoute = !isHomePage
? baseRoute.routes.find((route) => {
return matchPath(location.pathname, route);
}) || {}
: {};
const {permalinkToSidebar, docsSidebars} = docsMetadata;
const sidebar = permalinkToSidebar[currentRoute.path];
const sidebar = isHomePage
? content.metadata.sidebar
: permalinkToSidebar[currentRoute.path];

return (
<Layout title="Doc page" description="My Doc page">
Expand Down
25 changes: 23 additions & 2 deletions packages/docusaurus-theme-bootstrap/src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ import {
NavItem as NavItemBase,
} 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 activeBaseUrl = useBaseUrl(activeBasePath);
const normalizedHref = useBaseUrl(href, true);

return (
<NavItemBase>
Expand All @@ -29,10 +40,20 @@ function NavItem({href, label, to, ...props}) {
? {
target: '_blank',
rel: 'noopener noreferrer',
href,
href: prependBaseUrlToHref ? normalizedHref : href,
}
: {
isNavLink: true,
activeClassName,
to: toUrl,
...(activeBasePath || activeBaseRegex
? {
isActive: (_match, location) =>
activeBaseRegex
? new RegExp(activeBaseRegex).test(location.pathname)
: location.pathname.startsWith(activeBaseUrl),
}
: null),
})}
{...props}>
{label}
Expand Down