Restore post metadata and align comments
Some checks are pending
Build / build (push) Waiting to run
Some checks are pending
Build / build (push) Waiting to run
This commit is contained in:
parent
5f146e3ef4
commit
4b3aa3022e
24 changed files with 400 additions and 95 deletions
|
|
@ -1,3 +1,14 @@
|
|||
import { format } from "date-fns";
|
||||
|
||||
const getReadingTime = (body: string | undefined) => {
|
||||
const words = (body ?? "")
|
||||
.replace(/```[\s\S]*?```/g, " ")
|
||||
.replace(/<[^>]+>/g, " ")
|
||||
.match(/\b[\w'-]+\b/g);
|
||||
|
||||
return Math.max(1, Math.ceil((words?.length ?? 0) / 220));
|
||||
};
|
||||
|
||||
const BlogPost = ({
|
||||
post,
|
||||
children,
|
||||
|
|
@ -5,12 +16,19 @@ const BlogPost = ({
|
|||
post: any;
|
||||
children: React.ReactNode;
|
||||
}) => {
|
||||
const { title } = post.data;
|
||||
const { title, pubDate } = post.data;
|
||||
const readingTime = getReadingTime(post.body);
|
||||
|
||||
return (
|
||||
<section className="container px-6 py-2 md:py-6">
|
||||
<article className="poetry-post mx-auto">
|
||||
<h1 className="poetry-post-title">{title}</h1>
|
||||
<div className="poetry-post-meta">
|
||||
<time dateTime={pubDate.toISOString()}>
|
||||
{format(pubDate, "MMMM d, yyyy")}
|
||||
</time>
|
||||
<span>{readingTime} min read</span>
|
||||
</div>
|
||||
<div className="poetry-post-body">{children}</div>
|
||||
</article>
|
||||
</section>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue