You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
744 B
34 lines
744 B
import React from "react";
|
|
import Router from "next/router";
|
|
import ReactMarkdown from "react-markdown";
|
|
|
|
export type PostProps = {
|
|
id: number;
|
|
title: string;
|
|
author: {
|
|
name: string;
|
|
email: string;
|
|
} | null;
|
|
content: string;
|
|
published: boolean;
|
|
};
|
|
|
|
const Post: React.FC<{ post: PostProps }> = ({ post }) => {
|
|
const authorName = post.author ? post.author.name : "Unknown author";
|
|
return (
|
|
<div onClick={() => Router.push("/p/[id]", `/p/${post.id}`)}>
|
|
<h2>{post.title}</h2>
|
|
<small>By {authorName}</small>
|
|
<ReactMarkdown children={post.content} />
|
|
<style jsx>{`
|
|
div {
|
|
color: inherit;
|
|
padding: 2rem;
|
|
}
|
|
`}</style>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Post;
|