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

@@ -21,6 +21,9 @@ const getSiteInfo = () => {
export default defineConfig({ export default defineConfig({
...getSiteInfo(), ...getSiteInfo(),
output: 'static', output: 'static',
server: {
allowedHosts: true,
},
integrations: [mdx(), sitemap(), icon(), compress({ integrations: [mdx(), sitemap(), icon(), compress({
HTML: false, HTML: false,
}), robotsTxt()], }), robotsTxt()],

View File

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

View File

@@ -35,7 +35,13 @@ const jsonLd = await profile.getJsonLd();
/> />
</a> </a>
<a class="title" href={`/posts/${post.id}`}><h3>{post.data.title}</h3></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>
))} ))}
</div> </div>