1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 05:41:31 +00:00

Feature: Add reading time to posts

This commit is contained in:
Cotes Chung
2020-12-17 15:17:21 +08:00
parent 87ba30a393
commit b9ffe15ffb
6 changed files with 66 additions and 24 deletions

15
_includes/read-time.html Normal file
View File

@@ -0,0 +1,15 @@
<!--
Calculate the post's reading time, and display the word count in tooltip
-->
{% assign words = include.content | strip_html | number_of_words: "auto" %}
{% assign read_time = words | divided_by: site.data.read_time.wpm %}
{% unless read_time > 0 %}
{% assign read_time = site.data.read_time.min_time %}
{% endunless %}
<!-- return element -->
<span class="readtime" data-toggle="tooltip" data-placement="bottom" title="{{ words }} words">
{{- read_time -}}{{" "}}{{- site.data.read_time.prompt -}}
</span>