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"
22import { remarkCodeHike } from "../src/index"
33import { compile } from "@mdx-js/mdx"
44import theme from "shiki/themes/slack-dark.json"
5+ import { withDebugger } from "mdx-debugger"
56
67export async function getFiles ( ) {
78 const files = await fs . promises . readdir ( "./dev/content" )
@@ -19,14 +20,22 @@ export async function getContent(filename: string) {
1920}
2021
2122export 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+
2231 const code = String (
23- await compile ( file , {
32+ await debugCompile ( file , {
2433 outputFormat : "function-body" ,
2534 remarkPlugins : [
2635 [ remarkCodeHike , { autoImport : false , theme } ] ,
2736 ] ,
2837 } )
2938 )
3039
31- return code
40+ return { code, debugLink }
3241}
Original file line number Diff line number Diff line change 5858 "cssnano" : " ^4.1.10" ,
5959 "esbuild" : " ^0.13.2" ,
6060 "mdx-bundler" : " ^8.0.1" ,
61+ "mdx-debugger" : " ^0.2.0" ,
6162 "next" : " ^12.1.0" ,
6263 "react" : " ^17.0.2" ,
6364 "react-dom" : " ^17.0.2" ,
Original file line number Diff line number Diff line change @@ -17,11 +17,12 @@ export async function getStaticProps({ params }) {
1717
1818 const files = await getFiles ( )
1919 const content = await getContent ( name )
20- const code = await getCode ( content )
20+ const { code, debugLink } = await getCode ( content )
2121 return {
2222 props : {
2323 tests : files ,
2424 code,
25+ debugLink,
2526 current : name ,
2627 } ,
2728 }
@@ -31,8 +32,9 @@ export default function Page({
3132 current,
3233 code,
3334 tests,
34- content ,
35+ debugLink ,
3536} ) {
37+ console . log ( debugLink )
3638 const { default : Content } = runSync ( code , runtime )
3739 return (
3840 < div
@@ -44,7 +46,7 @@ export default function Page({
4446 } }
4547 >
4648 < Sidebar tests = { tests } current = { current } />
47- < Result Content = { Content } />
49+ < Result Content = { Content } debugLink = { debugLink } />
4850 </ div >
4951 )
5052}
@@ -77,7 +79,7 @@ function Sidebar({ tests, current }) {
7779 )
7880}
7981
80- function Result ( { Content } ) {
82+ function Result ( { Content, debugLink } ) {
8183 return (
8284 < div
8385 style = { {
@@ -86,8 +88,21 @@ function Result({ Content }) {
8688 background : "#fafafa" ,
8789 borderRadius : 4 ,
8890 padding : 16 ,
91+ position : "relative" ,
8992 } }
9093 >
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 >
91106 < Content components = { { CH } } />
92107 </ div >
93108 )
Original file line number Diff line number Diff line change @@ -6963,6 +6963,13 @@ mdx-bundler@^8.0.1:
69636963 uuid "^8.3.2"
69646964 xdm "^3.3.0"
69656965
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+
69666973meant@^1.0.1:
69676974 version "1.0.3"
69686975 resolved "https://registry.yarnpkg.com/meant/-/meant-1.0.3.tgz#67769af9de1d158773e928ae82c456114903554c"
You can’t perform that action at this time.
0 commit comments