CoastalCommitsPastes/client/pages/post/[id].tsx

50 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { GetStaticPaths, GetStaticProps } from "next";
import type { Post } from "@lib/types";
import PostPage from "@components/post-page";
2022-03-15 22:49:41 -04:00
export type PostProps = {
2022-03-21 21:51:19 -04:00
post: Post
}
2022-03-15 22:49:41 -04:00
const PostView = ({ post }: PostProps) => {
return <PostPage post={post} />
2022-03-06 19:46:59 -05:00
}
export const getStaticPaths: GetStaticPaths = async () => {
const posts = await fetch(process.env.API_URL + `/posts/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-secret-key": process.env.SECRET_KEY || "",
}
})
const json = await posts.json()
const filtered = json.filter((post: any) => post.visibility === "public" || post.visibility === "unlisted")
const paths = filtered.map((post: any) => ({
params: { id: post.id }
}))
return { paths, fallback: 'blocking' }
}
export const getStaticProps: GetStaticProps = async ({ params }) => {
const post = await fetch(process.env.API_URL + `/posts/${params?.id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-secret-key": process.env.SECRET_KEY || "",
}
})
2022-03-15 22:49:41 -04:00
return {
props: {
post: await post.json()
},
2022-03-15 22:49:41 -04:00
}
}
export default PostView
2022-03-21 18:55:21 -04:00