added reading time in single page

This commit is contained in:
gurusabarish
2023-01-21 23:31:22 +05:30
parent 07c0b9652f
commit 1d476eb2b5
3 changed files with 26 additions and 0 deletions
+6
View File
@@ -363,3 +363,9 @@ params:
# List pages like blogs and posts
listPages:
disableFeaturedImage: false
# Single pages like blog and post
singlePages:
readTime:
enable: false
content: "min read"
+10
View File
@@ -22,6 +22,12 @@
{{ .Params.author }}
<small>|</small>
{{ .Date.Format "Jan 2, 2006" }}
{{ if or (.Site.Params.singlePages.readTime.enable | default true) (.Params.enableReadingTime) }}
<span id="readingTime">
{{ .Site.Params.singlePages.readTime.content | default "min read" }}
</span>
{{ end }}
</div>
</div>
{{ if .Params.image }}
@@ -114,4 +120,8 @@
}
</script>
{{ if or (.Site.Params.singlePages.readTime.enable | default true) (.Params.enableReadingTime) }}
<script src="{{.Site.Params.staticPath}}/js/readingTime.js"></script>
{{end}}
{{ end }}
+10
View File
@@ -0,0 +1,10 @@
function readingTime() {
const text = document.querySelector("article").innerText;
const wpm = 225;
const words = text.trim().split(/\s+/).length;
const time = Math.ceil(words / wpm);
const timeElement = document.querySelector("span#readingTime");
timeElement.innerHTML = "<small> | </small>" + time + timeElement.innerHTML;
}
readingTime();