mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-25 05:35:53 +00:00
Rename
This commit is contained in:
39
example/pages/posts/[id].js
Normal file
39
example/pages/posts/[id].js
Normal file
@@ -0,0 +1,39 @@
|
||||
import Layout from '../../components/layout'
|
||||
import { getAllPostIds, getPostData } from '../../lib/posts'
|
||||
import Head from 'next/head'
|
||||
import Date from '../../components/date'
|
||||
import utilStyles from '../../styles/utils.module.css'
|
||||
|
||||
export default function Post({ postData }) {
|
||||
return (
|
||||
<Layout>
|
||||
<Head>
|
||||
<title>{postData.title}</title>
|
||||
</Head>
|
||||
<article>
|
||||
<h1 className={utilStyles.headingXl}>{postData.title}</h1>
|
||||
<div className={utilStyles.lightText}>
|
||||
<Date dateString={postData.date} />
|
||||
</div>
|
||||
<div dangerouslySetInnerHTML={{ __html: postData.contentHtml }} />
|
||||
</article>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const paths = getAllPostIds()
|
||||
return {
|
||||
paths,
|
||||
fallback: false
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }) {
|
||||
const postData = await getPostData(params.id)
|
||||
return {
|
||||
props: {
|
||||
postData
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user