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
Showing
2 changed files
with
34 additions
and
35 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
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 |
---|---|---|
@@ -1,39 +1,30 @@ | ||
import { getPost, getPostIds, Post } from "lib/posts"; | ||
import { NextPage } from "next"; | ||
import React from 'react'; | ||
import {GetServerSideProps, NextPage} from 'next'; | ||
import {getDatabaseConnection} from '../../lib/getDatabaseConnection'; | ||
import {Post} from '../../src/entity/Post'; | ||
|
||
type Props = { | ||
post: Post | ||
post: Post | ||
} | ||
const postShow: NextPage<Props> = (props) => { | ||
const { post } = props | ||
return ( | ||
<div> | ||
文章详情 | ||
<h1>{post.title}</h1> | ||
<article dangerouslySetInnerHTML={{ __html: post.htmlContent }}> | ||
</article> | ||
const postsShow: NextPage<Props> = (props) => { | ||
const {post} = props; | ||
return ( | ||
<div> | ||
<h1>{post.title}</h1> | ||
<article dangerouslySetInnerHTML={{__html: post.content}}> | ||
</article> | ||
</div> | ||
); | ||
}; | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default postShow; | ||
|
||
export const getStaticPaths = async () => { | ||
const idList = await getPostIds(); | ||
console.log(idList) | ||
return { | ||
paths: idList.map(id => ({ params: { id: id } })), | ||
fallback: false | ||
} | ||
} | ||
export default postsShow; | ||
|
||
export const getStaticProps = async (x: any) => { | ||
const id = x.params.id; | ||
const post = await getPost(id); | ||
return { | ||
props: { | ||
post: JSON.parse(JSON.stringify(post)) | ||
} | ||
} | ||
} | ||
export const getServerSideProps: GetServerSideProps<any, { id: string }> = async (context) => { | ||
const connection = await getDatabaseConnection(); | ||
const post = await connection.manager.findOne(Post, context.params.id); | ||
return { | ||
props: { | ||
post: JSON.parse(JSON.stringify(post)) | ||
} | ||
}; | ||
}; |