From 5948ea43e2be72c8c93195ffe0d73625af9ed4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Felipe=20Gon=C3=A7alves?= Date: Tue, 30 May 2023 13:47:19 +0000 Subject: [PATCH] feat(contentlayer): add reading_time computed field on Post definitions --- content/definitions/Post.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content/definitions/Post.ts b/content/definitions/Post.ts index b8c1c868..484aa07d 100644 --- a/content/definitions/Post.ts +++ b/content/definitions/Post.ts @@ -1,4 +1,5 @@ import { defineDocumentType, defineNestedType } from 'contentlayer/source-files' +import readingTime from 'reading-time' import { slug } from '../../src/shared/lib/slug' import { authors } from './author-list' @@ -76,6 +77,10 @@ export const Post = defineDocumentType(() => ({ type: 'nested', of: Author, resolve: post => authors.find(author => author.user === post.author) + }, + reading_time: { + type: 'json', + resolve: post => readingTime(post.body.raw) } } }))