Skip to content

Commit b8741ca

Browse files
authored
Merge pull request #175 from code-hike/next
v0.5
2 parents 76a6304 + 9b3a67b commit b8741ca

Some content is hidden

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

59 files changed

+1762
-580
lines changed

contributing.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Files and Folders
2+
3+
- `packages/mdx`: the npm package
4+
- `packages/mdx/vite.config.js`: we only use vite for testing with vitest
5+
- `packages/mdx/rollup.config.js`: rollup builds the thing we release to npm
6+
- `packages/mdx/next.config.js`: we have a nextjs testing site, our poor man's storybook
7+
- `packages/mdx/pages`: the pages for the nextjs test site
8+
- `packages/mdx/dev`: code and content used by the nextjs test site
9+
- `packages/mdx/src/remark`: the code that runs at build time when you compile an mdx file
10+
- `examples`: a list of examples, most of them use the Code Hike version from `packages/mdx/dist`
11+
- `examples/bundle-test`: this one is used by `.github/workflows/bundle-analysis.yml`

examples/contentlayer/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["next/babel"]
3+
}

examples/contentlayer/.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
37+
38+
# Contentlayer
39+
.contentlayer

examples/contentlayer/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Next.js + Contentlayer + Code Hike
2+
3+
See [this guide](https://codehike.org/docs/installation/contentlayer).
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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/dark-plus.json")
6+
7+
const Post = defineDocumentType(() => ({
8+
name: "Post",
9+
filePathPattern: `**/*.mdx`,
10+
contentType: "mdx",
11+
fields: {
12+
title: {
13+
type: "string",
14+
description: "The title of the post",
15+
required: true,
16+
},
17+
},
18+
computedFields: {
19+
url: {
20+
type: "string",
21+
resolve: (doc) => `/posts/${doc._raw.flattenedPath}`,
22+
},
23+
},
24+
}))
25+
26+
export default makeSource({
27+
contentDirPath: "posts",
28+
documentTypes: [Post],
29+
30+
mdx: { remarkPlugins: [[remarkCodeHike, { theme }]] },
31+
})

examples/contentlayer/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

examples/contentlayer/next.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { withContentlayer } = require("next-contentlayer")
2+
3+
module.exports = withContentlayer(
4+
{} // Next.js config here
5+
)

examples/contentlayer/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "codehike-contentlayer",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "INIT_CWD=$PWD next build",
8+
"start": "next start"
9+
},
10+
"dependencies": {
11+
"@code-hike/mdx": "^0.4.0",
12+
"@types/node": "^17.0.30",
13+
"contentlayer": "latest",
14+
"next": "^12.1.0",
15+
"next-contentlayer": "latest",
16+
"react": "^17.0.2",
17+
"react-dom": "^17.0.2"
18+
},
19+
"devDependencies": {
20+
"@types/react": "^17.0.2",
21+
"typescript": "4.6.3"
22+
}
23+
}

examples/contentlayer/pages/_app.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "@code-hike/mdx/dist/index.css"
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp

examples/contentlayer/pages/index.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Link from "next/link"
2+
import { allPosts, Post } from "contentlayer/generated"
3+
4+
export async function getStaticProps() {
5+
return { props: { posts: allPosts } }
6+
}
7+
8+
export default function Home({ posts }: { posts: Post[] }) {
9+
return (
10+
<div>
11+
<h1>A Blog</h1>
12+
Posts:
13+
<ul>
14+
{posts.map((post, idx) => (
15+
<li key={idx}>
16+
<Link href={post.url}>
17+
<a>{post.title}</a>
18+
</Link>
19+
</li>
20+
))}
21+
</ul>
22+
</div>
23+
)
24+
}

0 commit comments

Comments
 (0)