Skip to content

Commit c876789

Browse files
committed
Ditch mdx-bundler
1 parent 4b940f2 commit c876789

File tree

10 files changed

+130
-180
lines changed

10 files changed

+130
-180
lines changed

.gitpod.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/mdx/next.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { remarkCodeHike } = require("@code-hike/mdx")
2+
const theme = require("shiki/themes/nord.json")
3+
4+
const withMDX = require("@next/mdx")({
5+
extension: /\.mdx?$/,
6+
options: {
7+
remarkPlugins: [[remarkCodeHike, { theme }]],
8+
},
9+
})
10+
11+
module.exports = withMDX({
12+
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
13+
14+
async redirects() {
15+
return [
16+
{
17+
source: "/",
18+
destination: "/test",
19+
permanent: false,
20+
},
21+
]
22+
},
23+
})

packages/mdx/pages/[name].tsx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { compile, runSync } from "@mdx-js/mdx"
2+
import * as runtime from "react/jsx-runtime.js"
3+
import fs from "fs"
4+
import { remarkCodeHike } from "../src/index"
5+
import { CH } from "../src/components"
6+
import theme from "shiki/themes/slack-dark.json"
7+
import Link from "next/link"
8+
9+
export async function getServerSideProps({ params }) {
10+
const files = await fs.promises.readdir("./tests/")
11+
12+
const tests = files
13+
.filter(filename => filename.endsWith(".mdx"))
14+
.map(filename => filename.slice(0, -4))
15+
16+
const { name = "test" } = params
17+
const mdxSource = await fs.promises.readFile(
18+
`./tests/${name}.mdx`,
19+
"utf8"
20+
)
21+
try {
22+
const props = {
23+
tests,
24+
current: name,
25+
code: String(
26+
await compile(mdxSource, {
27+
outputFormat: "function-body",
28+
remarkPlugins: [
29+
[remarkCodeHike, { autoImport: false, theme }],
30+
],
31+
})
32+
),
33+
}
34+
return { props }
35+
} catch (e) {
36+
console.error(
37+
"getServerSideProps error",
38+
JSON.stringify(e, null, 2)
39+
)
40+
}
41+
return { props: { error: true, tests, current: name } }
42+
}
43+
44+
export default function Page({ current, code, tests }) {
45+
const { default: Content } = runSync(code, runtime)
46+
return (
47+
<div
48+
style={{
49+
display: "flex",
50+
flexDirection: "row",
51+
gap: 8,
52+
margin: "8px",
53+
}}
54+
>
55+
<nav
56+
style={{
57+
background: "#fafafa",
58+
borderRadius: 4,
59+
padding: 16,
60+
minWidth: 180,
61+
}}
62+
>
63+
<ul style={{ margin: 0, padding: 0 }}>
64+
{tests.map(test => (
65+
<li key={test} style={{ listStyle: "none" }}>
66+
<Link href={`/${encodeURIComponent(test)}`}>
67+
<a
68+
style={{
69+
color: "black",
70+
textDecoration: "none",
71+
fontWeight:
72+
test === current ? "bold" : "normal",
73+
}}
74+
>
75+
{test}
76+
</a>
77+
</Link>
78+
</li>
79+
))}
80+
</ul>
81+
</nav>
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 }} />
92+
</div>
93+
</div>
94+
)
95+
}

packages/mdx/pages/index.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

packages/mdx/pages/styles.css

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ body > div:first-child,
44
div#__next,
55
div#__next > div {
66
margin: 0;
7-
height: 100%;
8-
max-height: 100%;
9-
display: flex;
10-
flex-direction: column;
117
font-family: sans-serif;
128
background-color: #444;
9+
/* height: 100%;
10+
max-height: 100%;
11+
display: flex;
12+
flex-direction: column; */
1313
/* --ch-scrollycoding-code-min-height: 500px;
1414
--ch-scrollycoding-sticker-width: 500px; */
1515
}
16-
16+
/*
1717
nav {
1818
height: 40px;
1919
overflow: hidden;
@@ -22,10 +22,10 @@ nav {
2222
main {
2323
flex: 1;
2424
overflow: auto;
25-
}
25+
} */
2626

2727
/* main */
28-
28+
/*
2929
.columns {
3030
display: flex;
3131
min-height: 100%;
@@ -55,11 +55,9 @@ main {
5555
border-radius: 6px;
5656
}
5757
58-
/* nav */
5958
6059
nav {
6160
display: flex;
62-
/* justify-content: space-evenly; */
6361
align-items: center;
6462
background-color: #222;
6563
color: #ccc;
@@ -100,18 +98,17 @@ nav .version {
10098
10199
nav label {
102100
margin-right: 24px;
103-
}
101+
} */
104102

105-
nav select {
103+
/* nav select {
106104
margin-left: 6px;
107105
border-radius: 4px;
108106
background-color: #fafafa;
109107
height: 24px;
110-
/* overflow: hidden; */
111-
}
108+
} */
112109

113110
/* result */
114-
111+
/*
115112
.result {
116113
min-width: 900px;
117114
width: 900px;
@@ -125,4 +122,4 @@ pre.shiki {
125122
.tailwind-font code {
126123
font-family: ui-monospace, SFMono-Regular, Consolas,
127124
"Liberation Mono", Menlo, monospace;
128-
}
125+
} */
File renamed without changes.

packages/mdx/tests/custom-annotations.mdx

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/mdx/tests/custom-annotations/MyTooltipAnnotation.jsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/mdx/tests/show-references.mdx

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/mdx/tests/with-links.mdx

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)