Initial commit from Create Next App
This commit is contained in:
45
pages/index.js
Normal file
45
pages/index.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import fs from 'fs'
|
||||
import matter from 'gray-matter'
|
||||
import Link from 'next/link'
|
||||
import path from 'path'
|
||||
import Layout from '../components/Layout'
|
||||
import { postFilePaths, POSTS_PATH } from '../utils/mdxUtils'
|
||||
|
||||
export default function Index({ posts }) {
|
||||
return (
|
||||
<Layout>
|
||||
<h1>Home Page</h1>
|
||||
<p>
|
||||
Click the link below to navigate to a page generated by{' '}
|
||||
<code>next-mdx-remote</code>.
|
||||
</p>
|
||||
<ul>
|
||||
{posts.map((post) => (
|
||||
<li key={post.filePath}>
|
||||
<Link
|
||||
as={`/posts/${post.filePath.replace(/\.mdx?$/, '')}`}
|
||||
href={`/posts/[slug]`}
|
||||
>
|
||||
<a>{post.data.title}</a>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
export function getStaticProps() {
|
||||
const posts = postFilePaths.map((filePath) => {
|
||||
const source = fs.readFileSync(path.join(POSTS_PATH, filePath))
|
||||
const { content, data } = matter(source)
|
||||
|
||||
return {
|
||||
content,
|
||||
data,
|
||||
filePath,
|
||||
}
|
||||
})
|
||||
|
||||
return { props: { posts } }
|
||||
}
|
Reference in New Issue
Block a user