@@ -2,7 +2,7 @@ import { runSync } from "@mdx-js/mdx"
22import * as runtime from "react/jsx-runtime.js"
33import { CH } from "../src/components"
44import Link from "next/link"
5- import { getCode , getFiles } from "../dev/files"
5+ import { getCode , getContent , getFiles } from "../dev/files"
66
77export async function getStaticPaths ( ) {
88 const files = await getFiles ( )
@@ -14,8 +14,10 @@ export async function getStaticPaths() {
1414
1515export async function getStaticProps ( { params } ) {
1616 const { name = "test" } = params
17+
1718 const files = await getFiles ( )
18- const code = await getCode ( name )
19+ const content = await getContent ( name )
20+ const code = await getCode ( content )
1921 return {
2022 props : {
2123 tests : files ,
@@ -25,7 +27,12 @@ export async function getStaticProps({ params }) {
2527 }
2628}
2729
28- export default function Page ( { current, code, tests } ) {
30+ export default function Page ( {
31+ current,
32+ code,
33+ tests,
34+ content,
35+ } ) {
2936 const { default : Content } = runSync ( code , runtime )
3037 return (
3138 < div
@@ -36,44 +43,52 @@ export default function Page({ current, code, tests }) {
3643 margin : "8px" ,
3744 } }
3845 >
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 } } />
7792 </ div >
7893 )
7994}
0 commit comments