Skip to content

Instantly share code, notes, and snippets.

@andreaselia
Created January 14, 2021 14:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreaselia/aa2d44e3dde3b726d3affc4dec7d8b47 to your computer and use it in GitHub Desktop.
Save andreaselia/aa2d44e3dde3b726d3affc4dec7d8b47 to your computer and use it in GitHub Desktop.
vue / nuxt reading time for blog posts/articles
<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