From 5e1324adf5ee481ff43f86afda386532d961dea9 Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Sat, 10 Jan 2026 11:27:05 +0000 Subject: [PATCH] add reading time --- astro.config.ts | 3 +++ src/data/data.posts.ts | 2 ++ src/pages/index.astro | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/astro.config.ts b/astro.config.ts index c1bc495..1536f86 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -21,6 +21,9 @@ const getSiteInfo = () => { export default defineConfig({ ...getSiteInfo(), output: 'static', + server: { + allowedHosts: true, + }, integrations: [mdx(), sitemap(), icon(), compress({ HTML: false, }), robotsTxt()], diff --git a/src/data/data.posts.ts b/src/data/data.posts.ts index e8bf907..b2f8a5d 100644 --- a/src/data/data.posts.ts +++ b/src/data/data.posts.ts @@ -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', diff --git a/src/pages/index.astro b/src/pages/index.astro index d5bc4be..bd1d276 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -35,7 +35,13 @@ const jsonLd = await profile.getJsonLd(); />

{post.data.title}

-
+
+ + {" "}• {post.readingTime} min read +
))}