Skip to content

Commit 787b073

Browse files
authored
docs(v2): nav links activeBasePath (#2303)
* docs(v2): Nav links activeBasePath * rename activeBaseRoute to activeBasePath * fixes
1 parent c46bf90 commit 787b073

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

packages/docusaurus-init/templates/classic/docusaurus.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ module.exports = {
1414
src: 'img/logo.svg',
1515
},
1616
links: [
17-
{to: 'docs/doc1', label: 'Docs', position: 'left'},
17+
{
18+
to: 'docs/doc1',
19+
activeBasePath: 'docs',
20+
label: 'Docs',
21+
position: 'left',
22+
},
1823
{to: 'blog', label: 'Blog', position: 'left'},
1924
{
2025
href: 'https://github.com/facebook/docusaurus',

packages/docusaurus-init/templates/facebook/docusaurus.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ module.exports = {
2323
src: 'img/logo.svg',
2424
},
2525
links: [
26-
{to: 'docs/doc1', label: 'Docs', position: 'left'},
26+
{
27+
to: 'docs/doc1',
28+
activeBasePath: 'docs',
29+
label: 'Docs',
30+
position: 'left',
31+
},
2732
{to: 'blog', label: 'Blog', position: 'left'},
2833
// Please keep GitHub link to the right for consistency.
2934
{

packages/docusaurus-theme-classic/src/theme/Navbar/index.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,9 @@ import useLockBodyScroll from '@theme/hooks/useLockBodyScroll';
2121

2222
import styles from './styles.module.css';
2323

24-
function NavLink({activeBaseRoute, to, href, label, position, ...props}) {
24+
function NavLink({activeBasePath, to, href, label, position, ...props}) {
2525
const toUrl = useBaseUrl(to);
26-
const activeBaseUrl = useBaseUrl(activeBaseRoute);
27-
const activeBaseProps =
28-
activeBaseRoute != null
29-
? {
30-
isActive: (_match, location) =>
31-
location.pathname.startsWith(activeBaseUrl),
32-
}
33-
: {};
26+
const activeBaseUrl = useBaseUrl(activeBasePath);
3427

3528
return (
3629
<Link
@@ -44,7 +37,12 @@ function NavLink({activeBaseRoute, to, href, label, position, ...props}) {
4437
: {
4538
activeClassName: 'navbar__link--active',
4639
to: toUrl,
47-
...activeBaseProps,
40+
...(activeBasePath
41+
? {
42+
isActive: (_match, location) =>
43+
location.pathname.startsWith(activeBaseUrl),
44+
}
45+
: null),
4846
})}
4947
{...props}>
5048
{label}

website-1.x/blog/2019-12-30-docusaurus-2019-recap.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tags: [recap]
1616

1717
In 2018, we proposed to rebuild [Docusaurus from the ground up](https://github.com/facebook/docusaurus/issues/789). It involved a major rearchitecture effort - we created a content-centric CSS framework from scratch, a plugins system, and moved from static HTML pages to be a single page-app with prerendered routes. It was a wild adventure and a tough feat, especially with no dedicated FTE working on the project. With the help of [@endilie](https://github.com/endiliey), our ex-intern-turned-contributor-turned-maintainer, we made really good progress on D2 and are currently on version 2.0.0-alpha.40. All features in Docusaurus 1 except for translations have been ported over.
1818

19-
D2's killer features are **Dark Mode** and its **superb performance**. D2 has dark mode support out-of-the-box and its near effortless to create a dark mode-friendly documentation site. Endilie put in great effort into optimizing the performance of the site and a bunch of performance optimization tricks have been done under the hood by default - optimized images, prerendering every route to static HTML and client-side routing thereafter, prefetching assets needed by future navigations whenever the user hovers over a navigation link, etc.
19+
D2's killer features are **Dark Mode** and its **superb performance**. D2 has dark mode support out-of-the-box and it is near effortless to create a dark mode-friendly documentation site. Endilie put in great effort into optimizing the performance of the site and a bunch of performance optimization tricks have been done under the hood by default - optimized images, prerendering every route to static HTML and client-side routing thereafter, prefetching assets needed by future navigations whenever the user hovers over a navigation link, etc.
2020

2121
Last but not least, we implemented a plugins architecture and turned the repo into a [Lerna monorepo](https://github.com/facebook/docusaurus/tree/master/packages). We believe this plugin architecture will be helpful towards building a community and also allowing users to build their own features for their unique use cases.
2222

website/docs/docusaurus.config.js.md

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ module.exports = {
163163
links: [
164164
{
165165
to: 'docs/docusaurus.config.js',
166+
activeBasePath: 'docs',
166167
label: 'docusaurus.config.js',
167168
position: 'left',
168169
},

website/docs/theme-classic.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: '@docusaurus/theme-classic'
1111

1212
To remove the ability to switch on dark mode, there is an option `themeConfig.disableDarkMode`, which is implicitly set to `false`.
1313

14-
```js
14+
```js {5}
1515
// docusaurus.config.js
1616
module.exports = {
1717
...
@@ -26,15 +26,13 @@ module.exports = {
2626

2727
You can configure a default image that will be used for your meta tag, in particular `og:image` and `twitter:image`.
2828

29-
```js
29+
```js {5-7}
3030
// docusaurus.config.js
3131
module.exports = {
3232
...
3333
themeConfig: {
34-
/**
35-
* Relative to your site's "static" directory.
36-
* Cannot be SVGs. Can be external URLs too.
37-
*/
34+
// Relative to your site's "static" directory.
35+
// Cannot be SVGs. Can be external URLs too.
3836
image: 'img/docusaurus.png',
3937
...
4038
},
@@ -47,7 +45,7 @@ module.exports = {
4745

4846
You can add a logo and title to the navbar via `themeConfig.navbar`. Logo can be placed in [static folder](static-assets.md). Logo URL is set to base URL of your site by default. Although you can specify your own URL for the logo, if it is an external link, it will open in a new tab. You can also set a different logo for dark mode.
4947

50-
```js
48+
```js {6-12}
5149
// docusaurus.config.js
5250
module.exports = {
5351
...
@@ -70,7 +68,7 @@ module.exports = {
7068

7169
You can add links to the navbar via `themeConfig.navbar.links`:
7270

73-
```js
71+
```js {6-16}
7472
// docusaurus/config.js
7573
module.exports = {
7674
...
@@ -81,6 +79,9 @@ module.exports = {
8179
to: 'docs/docusaurus.config.js',
8280
label: 'docusaurus.config.js',
8381
position: 'left',
82+
// To apply the active class styling on all
83+
// routes starting with this path.
84+
activeBasePath: 'docs',
8485
},
8586
// ... other links
8687
],
@@ -90,13 +91,13 @@ module.exports = {
9091
}
9192
```
9293

93-
Outbound links automatically get `target="_blank" rel="noopener noreferrer"`.
94+
Outbound links automatically get `target="_blank" rel="noopener noreferrer"` attributes.
9495

9596
### Auto-hide sticky navbar
9697

9798
You can enable this cool UI feature that automatically hides the navbar when a user starts scrolling down the page, and show it again when the user scrolls up.
9899

99-
```js
100+
```js {6}
100101
// docusaurus/config.js
101102
module.exports = {
102103
...
@@ -137,7 +138,7 @@ module.exports = {
137138

138139
You can set a default language for code blocks if no language is added after the opening triple backticks (i.e. ```). Note that a valid [language name](https://prismjs.com/#supported-languages) must be passed, e.g.:
139140

140-
```js
141+
```js {6}
141142
// docusaurus/config.js
142143
module.exports = {
143144
...

website/docusaurus.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = {
9595
},
9696
{
9797
to: 'docs/introduction',
98-
activeBaseRoute: 'docs',
98+
activeBasePath: 'docs',
9999
label: 'Docs',
100100
position: 'left',
101101
},

0 commit comments

Comments
 (0)