File tree Expand file tree Collapse file tree 4 files changed +38
-6
lines changed Expand file tree Collapse file tree 4 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import fs from "fs"
2
2
import { remarkCodeHike } from "../src/index"
3
3
import { compile } from "@mdx-js/mdx"
4
4
import theme from "shiki/themes/slack-dark.json"
5
+ import { withDebugger } from "mdx-debugger"
5
6
6
7
export async function getFiles ( ) {
7
8
const files = await fs . promises . readdir ( "./dev/content" )
@@ -19,14 +20,22 @@ export async function getContent(filename: string) {
19
20
}
20
21
21
22
export async function getCode ( file : string ) {
23
+ let debugLink = ""
24
+
25
+ const debugCompile = withDebugger ( compile , {
26
+ log : ( path : string , url : string ) => {
27
+ debugLink = url
28
+ } ,
29
+ } )
30
+
22
31
const code = String (
23
- await compile ( file , {
32
+ await debugCompile ( file , {
24
33
outputFormat : "function-body" ,
25
34
remarkPlugins : [
26
35
[ remarkCodeHike , { autoImport : false , theme } ] ,
27
36
] ,
28
37
} )
29
38
)
30
39
31
- return code
40
+ return { code, debugLink }
32
41
}
Original file line number Diff line number Diff line change 58
58
"cssnano" : " ^4.1.10" ,
59
59
"esbuild" : " ^0.13.2" ,
60
60
"mdx-bundler" : " ^8.0.1" ,
61
+ "mdx-debugger" : " ^0.2.0" ,
61
62
"next" : " ^12.1.0" ,
62
63
"react" : " ^17.0.2" ,
63
64
"react-dom" : " ^17.0.2" ,
Original file line number Diff line number Diff line change @@ -17,11 +17,12 @@ export async function getStaticProps({ params }) {
17
17
18
18
const files = await getFiles ( )
19
19
const content = await getContent ( name )
20
- const code = await getCode ( content )
20
+ const { code, debugLink } = await getCode ( content )
21
21
return {
22
22
props : {
23
23
tests : files ,
24
24
code,
25
+ debugLink,
25
26
current : name ,
26
27
} ,
27
28
}
@@ -31,8 +32,9 @@ export default function Page({
31
32
current,
32
33
code,
33
34
tests,
34
- content ,
35
+ debugLink ,
35
36
} ) {
37
+ console . log ( debugLink )
36
38
const { default : Content } = runSync ( code , runtime )
37
39
return (
38
40
< div
@@ -44,7 +46,7 @@ export default function Page({
44
46
} }
45
47
>
46
48
< Sidebar tests = { tests } current = { current } />
47
- < Result Content = { Content } />
49
+ < Result Content = { Content } debugLink = { debugLink } />
48
50
</ div >
49
51
)
50
52
}
@@ -77,7 +79,7 @@ function Sidebar({ tests, current }) {
77
79
)
78
80
}
79
81
80
- function Result ( { Content } ) {
82
+ function Result ( { Content, debugLink } ) {
81
83
return (
82
84
< div
83
85
style = { {
@@ -86,8 +88,21 @@ function Result({ Content }) {
86
88
background : "#fafafa" ,
87
89
borderRadius : 4 ,
88
90
padding : 16 ,
91
+ position : "relative" ,
89
92
} }
90
93
>
94
+ < a
95
+ href = { debugLink }
96
+ target = "_blank"
97
+ rel = "noopener noreferrer"
98
+ style = { {
99
+ position : "absolute" ,
100
+ right : "16px" ,
101
+ top : "16px" ,
102
+ } }
103
+ >
104
+ Debug
105
+ </ a >
91
106
< Content components = { { CH } } />
92
107
</ div >
93
108
)
Original file line number Diff line number Diff line change @@ -6963,6 +6963,13 @@ mdx-bundler@^8.0.1:
6963
6963
uuid "^8.3.2"
6964
6964
xdm "^3.3.0"
6965
6965
6966
+ mdx-debugger@^0.2.0:
6967
+ version "0.2.0"
6968
+ resolved "https://registry.yarnpkg.com/mdx-debugger/-/mdx-debugger-0.2.0.tgz#c441bdc9790731774d837374d3acda01cc6f5e86"
6969
+ integrity sha512-xIgIhQszqkLWeh+RR0Y7m+2983EbHMuRmwY3gfDtamXnsi4NO32G88nTAEIDq7D0fV7Ml3BW3yT9dM7jTZjRzQ==
6970
+ dependencies:
6971
+ lz-string "^1.4.4"
6972
+
6966
6973
meant@^1.0.1:
6967
6974
version "1.0.3"
6968
6975
resolved "https://registry.yarnpkg.com/meant/-/meant-1.0.3.tgz#67769af9de1d158773e928ae82c456114903554c"
You can’t perform that action at this time.
0 commit comments