mirror of
https://github.com/vercel/next-learn.git
synced 2026-07-07 14:09:06 +00:00
Add typescript-final
This commit is contained in:
48
typescript-final/pages/posts/[id].tsx
Normal file
48
typescript-final/pages/posts/[id].tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
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'
|
||||
import { GetStaticProps, GetStaticPaths } from 'next'
|
||||
|
||||
export default function Post({
|
||||
postData
|
||||
}: {
|
||||
postData: {
|
||||
title: string
|
||||
date: string
|
||||
contentHtml: string
|
||||
}
|
||||
}) {
|
||||
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 const getStaticPaths: GetStaticPaths = async () => {
|
||||
const paths = getAllPostIds()
|
||||
return {
|
||||
paths,
|
||||
fallback: false
|
||||
}
|
||||
}
|
||||
|
||||
export const getStaticProps: GetStaticProps = async ({ params }) => {
|
||||
const postData = await getPostData(params.id as string)
|
||||
return {
|
||||
props: {
|
||||
postData
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user