Skip to content

Commit

Permalink
feat(contentlayer): add reading_time computed field on Post definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed May 30, 2023
1 parent 0221433 commit 5948ea4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions content/definitions/Post.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
}
}
}))

0 comments on commit 5948ea4

Please sign in to comment.