Skip to content

Commit ef0fc18

Browse files
Create Next.js
1 parent ac0e65f commit ef0fc18

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Next.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// First, create a package.json file in your repository root:
2+
{
3+
"name": "markdown-site",
4+
"version": "0.1.0",
5+
"private": true,
6+
"scripts": {
7+
"dev": "next dev",
8+
"build": "next build",
9+
"start": "next start"
10+
},
11+
"dependencies": {
12+
"next": "latest",
13+
"react": "latest",
14+
"react-dom": "latest",
15+
"gray-matter": "^4.0.3",
16+
"markdown-to-jsx": "^7.2.0"
17+
}
18+
}
19+
20+
// Create a next.config.js file:
21+
/** @type {import('next').NextConfig} */
22+
const nextConfig = {
23+
reactStrictMode: true,
24+
}
25+
26+
module.exports = nextConfig
27+
28+
// Create pages/_app.js:
29+
function MyApp({ Component, pageProps }) {
30+
return <Component {...pageProps} />
31+
}
32+
33+
export default MyApp
34+
35+
// Create pages/index.js:
36+
import fs from 'fs'
37+
import path from 'path'
38+
import matter from 'gray-matter'
39+
import Markdown from 'markdown-to-jsx'
40+
41+
export default function Home({ content }) {
42+
return (
43+
<div style={{ maxWidth: '800px', margin: '0 auto', padding: '20px' }}>
44+
<Markdown>{content}</Markdown>
45+
</div>
46+
)
47+
}
48+
49+
export async function getStaticProps() {
50+
// Read the README.md or your main markdown file
51+
const filePath = path.join(process.cwd(), 'README.md')
52+
const fileContent = fs.readFileSync(filePath, 'utf8')
53+
const { content } = matter(fileContent)
54+
55+
return {
56+
props: {
57+
content
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)