Skip to content

Commit 4b940f2

Browse files
authored
Merge pull request #147 from code-hike/monopackage
Monopackage refactor
2 parents 4d4298e + 13d428f commit 4b940f2

File tree

223 files changed

+12201
-13038
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+12201
-13038
lines changed

.github/workflows/release.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ jobs:
99
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
1010
steps:
1111
- uses: actions/checkout@v2
12-
with:
13-
fetch-depth: 10 # 👈 Required to retrieve git history
1412

1513
- name: Prepare repository
1614
run: git fetch --unshallow --tags
@@ -35,6 +33,7 @@ jobs:
3533
run: |
3634
yarn install --frozen-lockfile 2>&1 | grep -v '^[warning|info]'
3735
yarn build
36+
yarn test
3837
yarn release
3938
# - name: Publish to Chromatic
4039
# uses: chromaui/action@v1

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ yarn-error.log
99
.vscode
1010
storybook-static
1111
packages/playground/out
12-
packages/starter
12+
packages/starter
13+
14+
# Contentlayer
15+
.contentlayer

.gitpod.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# and commit this file to your remote git repository to share the goodness with others.
44

55
tasks:
6-
- init: yarn install && yarn run build
7-
command: yarn run playground
6+
- init: yarn install
87

98

examples/.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"semi": false
3+
}

examples/contentlayer/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.next
3+
.contentlayer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineDocumentType, makeSource } from "contentlayer/source-files"
2+
import { remarkCodeHike } from "@code-hike/mdx"
3+
import { createRequire } from "module"
4+
const require = createRequire(import.meta.url)
5+
const theme = require("shiki/themes/nord.json")
6+
7+
export const Post = defineDocumentType(() => ({
8+
name: "Post",
9+
contentType: "mdx",
10+
filePathPattern: "**/*.mdx",
11+
fields: {
12+
title: {
13+
type: "string",
14+
description: "The title of the post",
15+
required: true,
16+
},
17+
},
18+
}))
19+
20+
export default makeSource({
21+
contentDirPath: "posts",
22+
documentTypes: [Post],
23+
mdx: { remarkPlugins: [[remarkCodeHike, { theme }]] },
24+
})

examples/contentlayer/jsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"paths": {
5+
"contentlayer/generated": ["./.contentlayer/generated"]
6+
}
7+
}
8+
}

examples/contentlayer/next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { withContentlayer } = require('next-contentlayer')
2+
3+
module.exports = withContentlayer()({})

examples/contentlayer/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "codehike-contentlayer",
3+
"private": true,
4+
"version": "0.0.0",
5+
"dependencies": {
6+
"@code-hike/mdx": "^0.3.0",
7+
"next": "^12.0.10",
8+
"react": "17.0.2",
9+
"react-dom": "17.0.2"
10+
},
11+
"devDependencies": {
12+
"contentlayer": "^0.1.1",
13+
"next-contentlayer": "^0.1.1"
14+
}
15+
}

examples/contentlayer/pages/[slug].js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { allPosts } from "contentlayer/generated"
2+
import { useMDXComponent } from "next-contentlayer/hooks"
3+
4+
export async function getStaticPaths() {
5+
const paths = allPosts.map((_) => "/" + _._raw.flattenedPath)
6+
return {
7+
paths,
8+
fallback: false,
9+
}
10+
}
11+
12+
export async function getStaticProps({ params }) {
13+
const post = allPosts.find((_) => _._raw.flattenedPath === params.slug)
14+
return {
15+
props: {
16+
post,
17+
},
18+
}
19+
}
20+
21+
const Page = ({ post }) => {
22+
const Component = useMDXComponent(post.body.code)
23+
return (
24+
<article style={{ maxWidth: 800 }}>
25+
<h1>{post.title}</h1>
26+
<Component />
27+
</article>
28+
)
29+
}
30+
31+
export default Page

examples/contentlayer/pages/_app.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "@code-hike/mdx/styles"
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp

examples/contentlayer/pages/index.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { allPosts } from "contentlayer/generated"
2+
import Link from "next/link"
3+
4+
export const getStaticProps = async ({}) => {
5+
return {
6+
props: {
7+
posts: allPosts.map((post) => ({
8+
slug: post._raw.flattenedPath,
9+
title: post.title,
10+
})),
11+
},
12+
}
13+
}
14+
15+
const Home = ({ posts }) => {
16+
return (
17+
<ul>
18+
{posts.map(({ slug, title }) => (
19+
<li key={slug}>
20+
<Link href={`/${slug}`}>
21+
<a>{title}</a>
22+
</Link>
23+
</li>
24+
))}
25+
</ul>
26+
)
27+
}
28+
29+
export default Home

examples/contentlayer/posts/my.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
type: "Post"
3+
title: "Hello World"
4+
---
5+
6+
Lorem ipsum dolor sit amet.
7+
8+
```python hello.py
9+
print("Rendered with Code Hike")
10+
```
11+
12+
Lorem ipsum dolor sit amet.

examples/mdx-bundler/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.next

examples/mdx-bundler/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "codehike-mdx-bundler",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"build": "next build"
7+
},
8+
"dependencies": {
9+
"@code-hike/mdx": "^0.3.0",
10+
"esbuild": "^0.14.23",
11+
"mdx-bundler": "^8.0.1",
12+
"next": "^12.1.0",
13+
"react": "^17.0.2",
14+
"react-dom": "^17.0.2"
15+
}
16+
}

examples/mdx-bundler/pages/_app.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "@code-hike/mdx/styles"
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp

examples/mdx-bundler/pages/index.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { remarkCodeHike } from "@code-hike/mdx"
2+
import theme from "shiki/themes/solarized-dark.json"
3+
import fs from "fs"
4+
import path from "path"
5+
import { bundleMDX } from "mdx-bundler"
6+
import { getMDXComponent } from "mdx-bundler/client"
7+
8+
export async function getStaticProps() {
9+
// can be from a local file, database, anywhere
10+
const source = fs.readFileSync("posts/lorem.mdx", "utf-8")
11+
12+
// https://github.com/kentcdodds/mdx-bundler#nextjs-esbuild-enoent
13+
if (process.platform === "win32") {
14+
process.env.ESBUILD_BINARY_PATH = path.join(
15+
process.cwd(),
16+
"node_modules",
17+
"esbuild",
18+
"esbuild.exe"
19+
)
20+
} else {
21+
process.env.ESBUILD_BINARY_PATH = path.join(
22+
process.cwd(),
23+
"node_modules",
24+
"esbuild",
25+
"bin",
26+
"esbuild"
27+
)
28+
}
29+
30+
const { code } = await bundleMDX({
31+
source,
32+
files: {},
33+
xdmOptions(options) {
34+
options.remarkPlugins = [
35+
...(options.remarkPlugins ?? []),
36+
[remarkCodeHike, { theme }],
37+
]
38+
return options
39+
},
40+
})
41+
42+
return { props: { source: code } }
43+
}
44+
45+
export default function Page({ source }) {
46+
const Content = getMDXComponent(source)
47+
return (
48+
<div style={{ width: 800, margin: "0 auto" }}>
49+
<Content />
50+
</div>
51+
)
52+
}

examples/mdx-bundler/posts/lorem.mdx

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Hello
2+
3+
Lorem ipsum dolor sit amet.
4+
5+
```python hello.py mark=1[22:30]
6+
print("Rendered with Code Hike")
7+
```
8+
9+
Lorem ipsum dolor sit amet.

examples/next-mdx-remote/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.next

examples/next-mdx-remote/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "codehike-next-mdx-remote",
3+
"private": true,
4+
"version": "0.0.0",
5+
"dependencies": {
6+
"@code-hike/mdx": "^0.3.0",
7+
"next": "^12.1.0",
8+
"next-mdx-remote": "^4.0.0",
9+
"react": "^17.0.2",
10+
"react-dom": "^17.0.2"
11+
}
12+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "@code-hike/mdx/styles"
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { serialize } from "next-mdx-remote/serialize"
2+
import { MDXRemote } from "next-mdx-remote"
3+
import { remarkCodeHike } from "@code-hike/mdx"
4+
import { CH } from "@code-hike/mdx/components"
5+
import theme from "shiki/themes/solarized-dark.json"
6+
import fs from "fs"
7+
8+
export async function getStaticProps() {
9+
// can be from a local file, database, anywhere
10+
const source = fs.readFileSync("posts/lorem.mdx")
11+
const mdxSource = await serialize(source, {
12+
mdxOptions: {
13+
remarkPlugins: [[remarkCodeHike, { autoImport: false, theme }]],
14+
useDynamicImport: true,
15+
},
16+
})
17+
return { props: { source: mdxSource } }
18+
}
19+
20+
export default function Page({ source }) {
21+
return (
22+
<div style={{ width: 800, margin: "0 auto" }}>
23+
<MDXRemote {...source} components={{ CH }} />
24+
</div>
25+
)
26+
}

0 commit comments

Comments
 (0)