added reading time in single page
This commit is contained in:
@@ -363,3 +363,9 @@ params:
|
|||||||
# List pages like blogs and posts
|
# List pages like blogs and posts
|
||||||
listPages:
|
listPages:
|
||||||
disableFeaturedImage: false
|
disableFeaturedImage: false
|
||||||
|
|
||||||
|
# Single pages like blog and post
|
||||||
|
singlePages:
|
||||||
|
readTime:
|
||||||
|
enable: false
|
||||||
|
content: "min read"
|
||||||
@@ -22,6 +22,12 @@
|
|||||||
{{ .Params.author }}
|
{{ .Params.author }}
|
||||||
<small>|</small>
|
<small>|</small>
|
||||||
{{ .Date.Format "Jan 2, 2006" }}
|
{{ .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>
|
||||||
</div>
|
</div>
|
||||||
{{ if .Params.image }}
|
{{ if .Params.image }}
|
||||||
@@ -114,4 +120,8 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{{ if or (.Site.Params.singlePages.readTime.enable | default true) (.Params.enableReadingTime) }}
|
||||||
|
<script src="{{.Site.Params.staticPath}}/js/readingTime.js"></script>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
@@ -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();
|
||||||
Reference in New Issue
Block a user