Skip to content

Commit f4f8bc3

Browse files
committed
Styling
1 parent c9eef1a commit f4f8bc3

File tree

7 files changed

+83
-2927
lines changed

7 files changed

+83
-2927
lines changed

packages/mdx/dev/files.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ export async function getFiles() {
99
.filter(file => file.endsWith(".mdx"))
1010
.map(filename => filename.slice(0, -4))
1111
}
12-
13-
export async function getCode(filename: string) {
12+
export async function getContent(filename: string) {
1413
const file = await fs.promises.readFile(
1514
`./dev/content/${filename}.mdx`,
1615
"utf8"
1716
)
1817

18+
return file
19+
}
20+
21+
export async function getCode(file: string) {
1922
const code = String(
2023
await compile(file, {
2124
outputFormat: "function-body",

packages/mdx/pages/[name].tsx

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { runSync } from "@mdx-js/mdx"
22
import * as runtime from "react/jsx-runtime.js"
33
import { CH } from "../src/components"
44
import Link from "next/link"
5-
import { getCode, getFiles } from "../dev/files"
5+
import { getCode, getContent, getFiles } from "../dev/files"
66

77
export async function getStaticPaths() {
88
const files = await getFiles()
@@ -14,8 +14,10 @@ export async function getStaticPaths() {
1414

1515
export 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
}

packages/mdx/pages/styles.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ div#__next > div {
1313
/* --ch-scrollycoding-code-min-height: 500px;
1414
--ch-scrollycoding-sticker-width: 500px; */
1515
}
16+
17+
.sidebar-link {
18+
font-size: 14px;
19+
}
20+
21+
.sidebar-link:hover {
22+
background: rgba(30, 167, 253, 0.1);
23+
}
24+
25+
.sidebar-link[data-active="true"] {
26+
background: rgba(30, 167, 253, 0.15);
27+
}
28+
29+
.sidebar-link a {
30+
padding: 2px 16px;
31+
display: block;
32+
text-decoration: none;
33+
color: black;
34+
}
35+
1636
/*
1737
nav {
1838
height: 40px;

0 commit comments

Comments
 (0)