add reading time

This commit is contained in:
Morten Olsen
2026-01-10 11:27:05 +00:00
committed by Morten Olsen
parent 86a9dc2d31
commit 5e1324adf5
3 changed files with 12 additions and 1 deletions

View File

@@ -3,7 +3,9 @@ import { profile } from "./data.profile";
class Posts {
#map = (post: CollectionEntry<'posts'>) => {
const readingTime = Math.ceil(post.body?.split(/\s+/g).length / 200) || 1;
return Object.assign(post, {
readingTime,
jsonLd: {
'@context': 'https://schema.org',
'@type': 'BlogPosting',

View File

@@ -35,7 +35,13 @@ const jsonLd = await profile.getJsonLd();
/>
</a>
<a class="title" href={`/posts/${post.id}`}><h3>{post.data.title}</h3></a>
<div class="subtitle"><AbsoluteTime datetime={post.data.pubDate} /></div>
<div class="subtitle">
<AbsoluteTime
datetime={post.data.pubDate}
format={{ month: "long", day: "numeric", year: "numeric" }}
/>
{" "}&bull; {post.readingTime} min read
</div>
</div>
))}
</div>