Skip to content

Commit 8e75084

Browse files
authored
Merge pull request #182 from code-hike/next
v0.5.1
2 parents 4097e7c + 1fe474f commit 8e75084

30 files changed

+1610
-96
lines changed

examples/contentlayer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Next.js + Contentlayer + Code Hike
22

3-
See [this guide](https://codehike.org/docs/installation/contentlayer).
3+
See [this guide](https://codehike.org/docs/installation/contentlayer) or try it on [Stackblitz](https://stackblitz.com/github/code-hike/codehike/tree/main/examples/contentlayer).

examples/contentlayer/posts/one.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Post one
3+
---
4+
5+
This is the first post.
6+
7+
```python hello.py
8+
# mark[16:24]
9+
print("This is Code Hike")
10+
```

examples/contentlayer/posts/post-one.mdx

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

examples/contentlayer/posts/post-two.mdx

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

examples/contentlayer/posts/two.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Post two
3+
---
4+
5+
This is the second post.
6+
7+
```js foo.js
8+
const x = 2
9+
```

packages/mdx/dev/content/expand.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<CH.Code>
2+
3+
```json package.json
4+
{
5+
"name": "package.json"
6+
}
7+
```
8+
9+
```js pages/index.js
10+
function IndexPage() {
11+
return 1
12+
}
13+
```
14+
15+
```js pages/post/[slug].js
16+
function PostPage() {
17+
return 1
18+
}
19+
```
20+
21+
---
22+
23+
```js pages/alpha.ts
24+
function AlphaPage() {
25+
return 1
26+
}
27+
```
28+
29+
```css src/styles.css
30+
.alpha {
31+
color: red;
32+
}
33+
```
34+
35+
```js src/comp.js
36+
function AlphaPage() {
37+
return <div className="alpha">1</div>
38+
}
39+
```
40+
41+
</CH.Code>

packages/mdx/dev/content/scrollycoding.mdx

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@ Start by installing next and react on an empty directory:
66
npm install next react react-dom
77
```
88

9-
<CH.Section>
10-
11-
Then also install the [mdx plugin for next](focus://1[13:21]), the [mdx loader](focus://1[23:36]), and [Code Hike](focus://1[38:56]).
12-
13-
```bash
14-
npm install @next/mdx @mdx-js/loader @code-hike/mdx@next
15-
```
9+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
1610

17-
</CH.Section>
11+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
1812

19-
<div style={{ height: "0.5em" }} />
13+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
2014

2115
<CH.Scrollycoding>
2216

@@ -28,6 +22,8 @@ Also, make sure you include `"md"` and `"mdx"` on the _`pageExtensions`_ setting
2822

2923
After this step, you can use MDX files in your project, but you can't use Code Hike yet.
3024

25+
<CH.Code>
26+
3127
{/* prettier-ignore */}
3228
```js next.config.js
3329
const withMDX = require("@next/mdx")({
@@ -45,6 +41,29 @@ module.exports = withMDX({
4541
})
4642
```
4743

44+
```js foo.js
45+
46+
```
47+
48+
```js barbarbar.js
49+
50+
```
51+
52+
```js bax.js
53+
54+
```
55+
56+
---
57+
58+
```css index.css
59+
.scrollycoding {
60+
overflow: auto;
61+
max-height: calc(100vh - 100px);
62+
}
63+
```
64+
65+
</CH.Code>
66+
4867
---
4968

5069
To set up Code Hike you need to [import the <CH.InlineCode>@code-hike/mdx</CH.InlineCode> plugin](focus://1,6[1:6]), and add it to the remarkPlugins array in the next.config.js file.
@@ -81,6 +100,8 @@ Then you need to create a `pages/_app.js` file if you don't have one.
81100

82101
You can find more information about the `_app.js` file in the [Next.js official docs](https://nextjs.org/docs/advanced-features/custom-app).
83102

103+
<CH.Code show={["pages/_app.js"]}>
104+
84105
{/* prettier-ignore */}
85106
```js pages/_app.js
86107
function MyApp({ Component, pageProps }) {
@@ -90,6 +111,8 @@ function MyApp({ Component, pageProps }) {
90111
export default MyApp
91112
```
92113

114+
</CH.Code>
115+
93116
---
94117

95118
The pages/\_app.js file is where you add global stylesheets in Next.js.
@@ -98,8 +121,14 @@ Here we need to import Code Hike's CSS.
98121

99122
If you want to customize Code Hike's styles with a global stylesheet make sure to import it after this import to avoid specificity issues.
100123

124+
<CH.Code show={["next.config.js", "pages/_app.js"]}>
125+
126+
```js next.config.js
127+
128+
```
129+
101130
{/* prettier-ignore */}
102-
```js pages/_app.js focus=1
131+
```js pages/_app.js focus=1 active
103132
import "@code-hike/mdx/dist/index.css"
104133

105134
function MyApp({ Component, pageProps }) {
@@ -109,12 +138,16 @@ function MyApp({ Component, pageProps }) {
109138
export default MyApp
110139
```
111140

141+
</CH.Code>
142+
112143
---
113144

114145
Now you can create mdx files using codehike.
115146

116147
Markdown (.md) files should also work.
117148

149+
<CH.Code show={["next.config.js","pages/my.mdx"]}>
150+
118151
{/* prettier-ignore */}
119152
~~~md pages/my.mdx
120153
# Hello
@@ -128,8 +161,16 @@ print("Rendered with Code Hike")
128161
Lorem ipsum dolor sit amet.
129162
~~~
130163

164+
</CH.Code>
165+
131166
</CH.Scrollycoding>
132167

133168
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
134169

170+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
171+
172+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
173+
135174
Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
175+
176+
<div style={{ height: "8em" }} />

packages/mdx/dev/content/section.mdx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Lorem ipsum dolor sit amet.
44

55
<CH.Section>
66

7-
Consectetur adipiscing elit, sed do eiusmod tempor [incididunt](focus://4:7) ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget.
8-
_`orem`_, _`sum`_
7+
Consectetur adipiscing elit, sed do eiusmod tempor [incididunt](focus://4:7) ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. _`rem(ipsum, dol`_ xxx
8+
_`orem`_, xxx _`sum`_
99

1010
```js
1111
function lorem(ipsum, dolor) {
@@ -49,3 +49,26 @@ function lorem(ipsum, dolor) {
4949
_`ackground-color: va`_
5050

5151
</CH.Section>
52+
53+
## Issue #117
54+
55+
<CH.Section>
56+
57+
{/* prettier-ignore */}
58+
```js
59+
const PostLayout = ({ post }) => {
60+
const MDXContent = useMDXComponent(
61+
post.body.code
62+
)
63+
return (
64+
<article style={{ width: 600 }}>
65+
<h1>{post.title}</h1>
66+
<MDXContent />
67+
</article>
68+
)
69+
}
70+
```
71+
72+
It transforms the _`post.body.code`_ into a React component.
73+
74+
</CH.Section>

packages/mdx/dev/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs"
22
import { remarkCodeHike } from "../src/index"
33
import { compile } from "@mdx-js/mdx"
4-
import theme from "shiki/themes/github-light.json"
4+
import theme from "shiki/themes/nord.json"
55
import { withDebugger } from "mdx-debugger"
66

77
export async function getFiles() {

packages/mdx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@types/diff": "^5.0.2",
5858
"@types/node": "^17.0.21",
5959
"@types/node-fetch": "^2.6.1",
60-
"@types/react": "^17.0.39",
60+
"@types/react": "17.0.45",
6161
"autoprefixer": "^9.8.2",
6262
"click-to-react-component": "^1.0.8",
6363
"cssnano": "^4.1.10",

0 commit comments

Comments
 (0)