@@ -2,7 +2,7 @@ import { runSync } from "@mdx-js/mdx"
2
2
import * as runtime from "react/jsx-runtime.js"
3
3
import { CH } from "../src/components"
4
4
import Link from "next/link"
5
- import { getCode , getFiles } from "../dev/files"
5
+ import { getCode , getContent , getFiles } from "../dev/files"
6
6
7
7
export async function getStaticPaths ( ) {
8
8
const files = await getFiles ( )
@@ -14,8 +14,10 @@ export async function getStaticPaths() {
14
14
15
15
export async function getStaticProps ( { params } ) {
16
16
const { name = "test" } = params
17
+
17
18
const files = await getFiles ( )
18
- const code = await getCode ( name )
19
+ const content = await getContent ( name )
20
+ const code = await getCode ( content )
19
21
return {
20
22
props : {
21
23
tests : files ,
@@ -25,7 +27,12 @@ export async function getStaticProps({ params }) {
25
27
}
26
28
}
27
29
28
- export default function Page ( { current, code, tests } ) {
30
+ export default function Page ( {
31
+ current,
32
+ code,
33
+ tests,
34
+ content,
35
+ } ) {
29
36
const { default : Content } = runSync ( code , runtime )
30
37
return (
31
38
< div
@@ -36,44 +43,52 @@ export default function Page({ current, code, tests }) {
36
43
margin : "8px" ,
37
44
} }
38
45
>
39
- < nav
40
- style = { {
41
- background : "#fafafa" ,
42
- borderRadius : 4 ,
43
- padding : 16 ,
44
- minWidth : 180 ,
45
- } }
46
- >
47
- < ul style = { { margin : 0 , padding : 0 } } >
48
- { tests . map ( test => (
49
- < li key = { test } style = { { listStyle : "none" } } >
50
- < Link href = { `/${ encodeURIComponent ( test ) } ` } >
51
- < a
52
- style = { {
53
- color : "black" ,
54
- textDecoration : "none" ,
55
- fontWeight :
56
- test === current ? "bold" : "normal" ,
57
- } }
58
- >
59
- { test }
60
- </ a >
61
- </ Link >
62
- </ li >
63
- ) ) }
64
- </ ul >
65
- </ nav >
66
- < div
67
- style = { {
68
- maxWidth : 900 ,
69
- minWidth : 600 ,
70
- background : "#fafafa" ,
71
- borderRadius : 4 ,
72
- padding : 16 ,
73
- } }
74
- >
75
- < Content components = { { CH } } />
76
- </ div >
46
+ < Sidebar tests = { tests } current = { current } />
47
+ < Result Content = { Content } />
48
+ </ div >
49
+ )
50
+ }
51
+
52
+ function Sidebar ( { tests, current } ) {
53
+ return (
54
+ < nav
55
+ style = { {
56
+ background : "#fafafa" ,
57
+ borderRadius : 4 ,
58
+ padding : "16px 0" ,
59
+ minWidth : 180 ,
60
+ } }
61
+ >
62
+ < ul style = { { margin : 0 , padding : 0 } } >
63
+ { tests . map ( test => (
64
+ < li
65
+ key = { test }
66
+ style = { { listStyle : "none" } }
67
+ className = "sidebar-link"
68
+ data-active = { test === current }
69
+ >
70
+ < Link href = { `/${ encodeURIComponent ( test ) } ` } >
71
+ < a > { test } </ a >
72
+ </ Link >
73
+ </ li >
74
+ ) ) }
75
+ </ ul >
76
+ </ nav >
77
+ )
78
+ }
79
+
80
+ function Result ( { Content } ) {
81
+ return (
82
+ < div
83
+ style = { {
84
+ maxWidth : 900 ,
85
+ minWidth : 600 ,
86
+ background : "#fafafa" ,
87
+ borderRadius : 4 ,
88
+ padding : 16 ,
89
+ } }
90
+ >
91
+ < Content components = { { CH } } />
77
92
</ div >
78
93
)
79
94
}
0 commit comments