Skip to content

Commit c299410

Browse files
committed
add: nextra Layout
1 parent 17d9134 commit c299410

File tree

18 files changed

+109
-24
lines changed

18 files changed

+109
-24
lines changed

apps/web/src/app/books/page.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import Aside from '@/features/bookEdit/components/Aside'
2-
31
function page() {
4-
return (
5-
<>
6-
<Aside />
7-
</>
8-
)
2+
return <></>
93
}
104

115
export default page
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.block {
2+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import NextraLayout from './NextraLayout'
2+
import { render } from '@testing-library/react'
3+
4+
describe('NextraLayout', () => {
5+
it('renders successfully', () => {
6+
render(<NextraLayout />)
7+
})
8+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useInternals } from '@packages/nextra-theme-docs'
2+
import styles from './NextraLayout.module.css'
3+
import { bindClassNames } from '@/lib/styles/bindClassNames'
4+
5+
const cx = bindClassNames(styles)
6+
7+
type Props = {
8+
children: React.ReactNode
9+
}
10+
11+
function NextraLayout({ children }: Props) {
12+
console.log('useInternals', useInternals)
13+
14+
return (
15+
<div className={cx('block')}>
16+
Nextral
17+
{children}
18+
</div>
19+
)
20+
}
21+
22+
export default NextraLayout
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './NextraLayout'

apps/web/src/features/bookEdit/components/Aside/Aside.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
'use client'
2-
31
import styles from './Aside.module.css'
42
import { bindClassNames } from '@/lib/styles/bindClassNames'
5-
import { Navbar } from '@packages/nextra-theme-docs'
6-
import { navbarFlatDirectories } from '../test/mock'
73

84
const cx = bindClassNames(styles)
95

106
function Aside() {
117
return (
128
<div className={cx('block')}>
139
<div>books</div>
14-
<Navbar flatDirectories={navbarFlatDirectories} items={[]} />
1510
</div>
1611
)
1712
}

apps/web/src/features/bookEdit/layout/BookEditLayout/BookEditLayout.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import styles from './BookEditLayout.module.css'
44
import { bindClassNames } from '@/lib/styles/bindClassNames'
5+
import NextraLayout from '@/components/Layouts/NextraLayout'
56

67
const cx = bindClassNames(styles)
78

@@ -10,7 +11,11 @@ type Props = {
1011
}
1112

1213
function BookEditLayout({ children }: Props) {
13-
return <div className={cx('block')}>{children}</div>
14+
return (
15+
<NextraLayout>
16+
<div className={cx('block')}>{children}</div>
17+
</NextraLayout>
18+
)
1419
}
1520

1621
export default BookEditLayout

apps/web/src/hooks/useCFUpload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import { useState } from 'react'
24

35
import { UploadImageArgs, uploadImage } from '@/lib/api/files'

apps/web/src/hooks/useCurrentPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function useCurrentPath() {
88
const search = useSearchParams()
99

1010
const currentPath = useMemo(() => {
11-
const query = search.toString()
11+
const query = search?.toString()
1212
return `${pathname === '/' ? '' : pathname}${query ? `?${query}` : ''}`
1313
}, [pathname, search])
1414

apps/web/src/hooks/useInputs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import { useReducer, useCallback, useMemo } from 'react'
24

35
type UseInputsAction = {

apps/web/src/hooks/useSearchPosts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import {
24
Post,
35
SearchPostsDocument,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Aside from '@/features/bookEdit/components/Aside'
2+
import BookEditLayout from '@/features/bookEdit/layout/BookEditLayout'
3+
4+
const BookEditPage = () => {
5+
return (
6+
<BookEditLayout>
7+
<Aside />
8+
</BookEditLayout>
9+
)
10+
}
11+
12+
export default BookEditPage

apps/web/tsconfig.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"compilerOptions": {
44
"baseUrl": "./",
55
"rootDir": "./",
6-
"typeRoots": ["node_modules/@types/", "./src/types/", "./node_modules/@packages/**/**/*.d.ts"],
6+
"typeRoots": [
7+
"node_modules/@types/",
8+
"./src/types/",
9+
"./node_modules/@packages/**/**/*.d.ts"
10+
],
711
"plugins": [
812
{
913
"name": "next"
@@ -13,9 +17,14 @@
1317
}
1418
],
1519
"paths": {
16-
"@/*": ["./src/*"],
17-
"@/public/*": ["./public/*"]
18-
}
20+
"@/*": [
21+
"./src/*"
22+
],
23+
"@/public/*": [
24+
"./public/*"
25+
]
26+
},
27+
"strictNullChecks": true
1928
},
2029
"include": [
2130
"next-env.d.ts",
@@ -28,5 +37,8 @@
2837
"eslint.config.js",
2938
".next/types/**/*.ts"
3039
],
31-
"exclude": ["node_modules", "dist"]
40+
"exclude": [
41+
"node_modules",
42+
"dist"
43+
]
3244
}

packages/nextra-theme-docs/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"lint": "eslint --fix"
3535
},
3636
"peerDependencies": {
37-
"next": ">=14.2.1",
38-
"nextra": "^2.13.4",
37+
"next": ">=9.5.3",
38+
"nextra": "2.13.4",
3939
"react": ">=16.13.1",
4040
"react-dom": ">=16.13.1"
4141
},
@@ -67,7 +67,7 @@
6767
"eslint": "^9.0.0",
6868
"jsdom": "^23.0.0",
6969
"next": "^14.2.1",
70-
"nextra": "^2.13.4",
70+
"nextra": "2.13.4",
7171
"postcss": "^8.4.31",
7272
"postcss-cli": "^10.1.0",
7373
"postcss-import": "^15.1.0",
@@ -81,4 +81,5 @@
8181
"sideEffects": [
8282
"./src/polyfill.ts"
8383
]
84+
8485
}

packages/nextra-theme-docs/src/constants.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,5 @@ export const DEEP_OBJECT_KEYS = Object.entries(DEFAULT_THEME)
339339
}
340340
})
341341
.filter(Boolean)
342+
343+
export const NEXTRA_INTERNAL = Symbol.for('__nextra_internal__')

packages/nextra-theme-docs/src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ const InnerLayout = ({
211211
)
212212
}
213213

214-
export default function Layout({ children, ...context }: NextraThemeLayoutProps): ReactElement {
214+
export default function NextraDocLayout({
215+
children,
216+
...context
217+
}: NextraThemeLayoutProps): ReactElement {
215218
return (
216219
<ConfigProvider value={context}>
217220
<InnerLayout {...context.pageOpts}>{children}</InnerLayout>
@@ -222,6 +225,7 @@ export default function Layout({ children, ...context }: NextraThemeLayoutProps)
222225
export { useConfig, PartialDocsThemeConfig as DocsThemeConfig }
223226
export { useMDXComponents } from 'nextra/mdx'
224227
export { Callout, Steps, Tabs, Tab, Cards, Card, FileTree } from 'nextra/components'
228+
225229
export { useTheme } from 'next-themes'
226230
export { Link } from './mdx-components'
227231
export {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { a as PageOpts } from 'nextra/dist/types-2e9b0ab5.js'
2+
import * as react from 'react'
3+
import 'gray-matter'
4+
import 'mdast'
5+
6+
/**
7+
* This hook is used to access the internal state of Nextra, you should never
8+
* use this hook in your application.
9+
*/
10+
declare function useInternals(): {
11+
context: {
12+
Content: react.FC
13+
pageOpts: PageOpts<{
14+
[key: string]: any
15+
}>
16+
themeConfig: any
17+
}
18+
Layout: react.FC<any>
19+
}
20+
21+
export { useInternals }

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)