Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created December 19, 2022 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/4771c33d2f6e96d1a167be8d2d271d59 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/4771c33d2f6e96d1a167be8d2d271d59 to your computer and use it in GitHub Desktop.
Set Reading Time on Blog/Article Page
<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