/set-reading-time.html Secret
Created
December 19, 2022 16:17
Set Reading Time on Blog/Article Page
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/reading-time/2.0.0/readingTime.js" integrity="sha256-aHKmycKpF87rkv79Pvc87nQCpWaJ4dvd90OwqqnmVMg=" crossorigin="anonymous"></script> | |
<script> | |
$(function () { | |
let content = $(".read-content")[0] | |
if (!content) {return;} | |
let txt = content.textContent; | |
wordCount = txt.replace( /[^\w ]/g, "" ).split( /\s+/ ).length; | |
let readingTimeInMinutes = Math.floor(wordCount / 228) + 1; | |
let readingTimeAsString = readingTimeInMinutes + " min"; | |
$('.read-time').html(readingTimeAsString); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment