1
Fork 0

Show reading time and optional synopsis instead of truncated post

This commit is contained in:
Jan-Erik Rediger 2022-01-30 00:47:43 +01:00
parent e723c89087
commit 7d6f4caa19

View file

@ -8,12 +8,39 @@ data:
{%- for post in collections.posts.pages -%} {%- for post in collections.posts.pages -%}
{%- if idx < 5 -%} {%- if idx < 5 -%}
<article class="blog-list"> <article class="blog-list">
<h3><a href="{{ post.permalink }}">{{ post.title }}</a></h3> <h1><a href="{{ post.permalink }}">{{ post.title }}</a></h1>
<time pubdate="pubdate">{{ post.published_date | date: "%b %d, %Y" }}</time><br /> <div class="metadata">
<p>{{ post.content | strip_html | truncatewords: 25, '...' }}</p> {% assign reading_wpm = 200 %}
{% assign word_count = post.content | split: " " | size %}
{% assign reading_time = word_count | divided_by: 200 %}
{% case reading_time %}
{% when 0 %}
{% assign phrase = "less than a minute." %}
{% when 1 %}
{% assign phrase = "about a minute." %}
{% else %}
{% assign phrase = " minute read" | prepend: reading_time %}
{% endcase %}
<time pubdate="pubdate">{{ post.published_date | date: "%b %d, %Y" }} · {{ phrase }}</time>
{% if post.data and post.data.tags -%}
{%- for tag in post.data.tags %}
· <a href="/tagged/{{ tag }}.html">{{ tag }}</a>
{%- endfor %}
{%- endif -%}
</div>
{%- if post.data and post.data.synopsis %}
<p>{{ post.data.synopsis | strip}}…</p>
{%- else %}
<p>{{ post.content | strip_html | truncatewords: 50, '…' }}</p>
{%- endif -%}
</article> </article>
<hr>
{%- endif -%} {%- endif -%}
{% assign idx = idx | plus: 1 %} {% assign idx = idx | plus: 1 %}
{%- endfor -%} {%- endfor -%}
<p>
Looking for more posts? Check out <a href="/posts/">all posts</a>! Looking for more posts? Check out <a href="/posts/">all posts</a>!
</p>