Created
January 14, 2021 14:05
-
-
Save andreaselia/aa2d44e3dde3b726d3affc4dec7d8b47 to your computer and use it in GitHub Desktop.
vue / nuxt reading time for blog posts/articles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div>{{ readingTime }} min read</div> | |
</template> | |
<script> | |
export default { | |
props: ['content'], | |
computed: { | |
readingTime () { | |
let minutes = 0 | |
const contentAsString = JSON.stringify(this.content) | |
const words = contentAsString.split(' ').length | |
const wordsPerMinute = 200 | |
minutes = Math.ceil(words / wordsPerMinute) | |
return minutes | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment