mirror of
https://github.com/morten-olsen/morten-olsen.github.io.git
synced 2026-02-07 17:36:29 +01:00
add reading time
This commit is contained in:
committed by
Morten Olsen
parent
86a9dc2d31
commit
5e1324adf5
@@ -21,6 +21,9 @@ const getSiteInfo = () => {
|
||||
export default defineConfig({
|
||||
...getSiteInfo(),
|
||||
output: 'static',
|
||||
server: {
|
||||
allowedHosts: true,
|
||||
},
|
||||
integrations: [mdx(), sitemap(), icon(), compress({
|
||||
HTML: false,
|
||||
}), robotsTxt()],
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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" }}
|
||||
/>
|
||||
{" "}• {post.readingTime} min read
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user