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