4
4
* This source code is licensed under the MIT license found in the
5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
- import React , { useState , useCallback , useEffect } from 'react'
7
+ import React , { useState , useCallback } from 'react'
8
8
import { MDXProvider } from '@mdx-js/react'
9
9
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
10
10
import renderRoutes from '@docusaurus/renderRoutes'
@@ -18,95 +18,15 @@ import { translate } from '@docusaurus/Translate'
18
18
import clsx from 'clsx'
19
19
import styles from './styles.module.css'
20
20
import { ThemeClassNames , docVersionSearchTag } from '@docusaurus/theme-common'
21
-
22
- function BraveWarning ( ) {
23
- const [ isBrave , setIsBrave ] = useState ( false )
24
-
25
- useEffect ( ( ) => {
26
- const check = async ( ) => {
27
- return ( navigator . brave && ( await navigator . brave . isBrave ( ) ) ) || false
28
- }
29
-
30
- check ( )
31
- . then ( ( isBrave ) => {
32
- if ( isBrave ) {
33
- setIsBrave ( isBrave )
34
- }
35
- } )
36
- . catch ( console . error )
37
- } , [ ] )
38
-
39
- return isBrave && ! localStorage . getItem ( 'brave-warning-dismissed' ) ? (
40
- < div className = "admonition admonition-caution alert alert--warning" >
41
- < div className = "admonition-heading" >
42
- < h5 >
43
- < span className = "admonition-icon" >
44
- < svg
45
- xmlns = "http://www.w3.org/2000/svg"
46
- width = "16"
47
- height = "16"
48
- viewBox = "0 0 16 16"
49
- >
50
- < path
51
- fill-rule = "evenodd"
52
- d = "M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"
53
- > </ path >
54
- </ svg >
55
- </ span >
56
- Brave Browser Warning
57
- </ h5 >
58
- </ div >
59
- < div className = "admonition-content" >
60
- < p >
61
- It appears that you're using Brave - that's awesome. We recommend
62
- disabling shields for this domain as well as CodeSandbox in the event
63
- that the examples do not load correctly.
64
- </ p >
65
- < button
66
- className = "button button--warning button--md"
67
- onClick = { ( ) => {
68
- localStorage . setItem ( 'brave-warning-dismissed' , true )
69
- setIsBrave ( false )
70
- } }
71
- >
72
- Dismiss
73
- </ button >
74
- </ div >
75
- </ div >
76
- ) : null
77
- }
78
-
79
- function getSidebar ( { versionMetadata, currentDocRoute } ) {
80
- function addTrailingSlash ( str ) {
81
- return str . endsWith ( '/' ) ? str : `${ str } /`
82
- }
83
-
84
- function removeTrailingSlash ( str ) {
85
- return str . endsWith ( '/' ) ? str . slice ( 0 , - 1 ) : str
86
- }
87
-
88
- const { permalinkToSidebar, docsSidebars } = versionMetadata // With/without trailingSlash, we should always be able to get the appropriate sidebar
89
- // note: docs plugin permalinks currently never have trailing slashes
90
- // trailingSlash is handled globally at the framework level, not plugin level
91
-
92
- const sidebarName =
93
- permalinkToSidebar [ currentDocRoute . path ] ||
94
- permalinkToSidebar [ addTrailingSlash ( currentDocRoute . path ) ] ||
95
- permalinkToSidebar [ removeTrailingSlash ( currentDocRoute . path ) ]
96
- const sidebar = docsSidebars [ sidebarName ]
97
- return {
98
- sidebar,
99
- sidebarName,
100
- }
101
- }
21
+ import BraveWarning from './BraveWarning'
102
22
103
23
function DocPageContent ( { currentDocRoute, versionMetadata, children } ) {
104
24
const { siteConfig, isClient } = useDocusaurusContext ( )
105
25
const { pluginId, version } = versionMetadata
106
- const { sidebarName, sidebar } = getSidebar ( {
107
- versionMetadata ,
108
- currentDocRoute ,
109
- } )
26
+ const sidebarName = currentDocRoute . sidebar
27
+ const sidebar = sidebarName
28
+ ? versionMetadata . docsSidebars [ sidebarName ]
29
+ : undefined
110
30
const [ hiddenSidebarContainer , setHiddenSidebarContainer ] = useState ( false )
111
31
const [ hiddenSidebar , setHiddenSidebar ] = useState ( false )
112
32
const toggleSidebar = useCallback ( ( ) => {
@@ -152,9 +72,7 @@ function DocPageContent({ currentDocRoute, versionMetadata, children }) {
152
72
}
153
73
sidebar = { sidebar }
154
74
path = { currentDocRoute . path }
155
- sidebarCollapsible = {
156
- siteConfig . themeConfig ?. sidebarCollapsible ?? true
157
- }
75
+ sidebarCollapsible = { siteConfig . themeConfig . sidebarCollapsible }
158
76
onCollapse = { toggleSidebar }
159
77
isHidden = { hiddenSidebar }
160
78
/>
@@ -227,7 +145,9 @@ function DocPage(props) {
227
145
currentDocRoute = { currentDocRoute }
228
146
versionMetadata = { versionMetadata }
229
147
>
230
- { renderRoutes ( docRoutes ) }
148
+ { renderRoutes ( docRoutes , {
149
+ versionMetadata,
150
+ } ) }
231
151
</ DocPageContent >
232
152
)
233
153
}
0 commit comments