-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac0e65f
commit ef0fc18
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} | ||
} |