Skip to content

Commit

Permalink
adding reading time for posts
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkersley committed Jan 26, 2016
1 parent c94bf64 commit 68ddaa3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions _includes/post-meta.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% capture read_time %}
{{ post.content | number_of_words | divided_by: 180 }}
{% endcapture %}
<p class="post-meta">
<time datetime="{{ post.date | date_to_xmlschema }}" itemprop="datePublished">{{ post.date | date: "%b %-d, %Y" }}</time> &bull;
{% if read_time != '0' %}
{{ read_time }}
{% else %}
1
{% endif %} min read
</p>
12 changes: 11 additions & 1 deletion _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">

<header class="post-header">
<p class="post-meta"><time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">{{ page.date | date: "%b %-d, %Y" }}</time>{% if page.author %} • <span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">{{ page.author }}</span></span>{% endif %}</p>
{% capture read_time %}
{{ page.content | number_of_words | divided_by: 180 }}
{% endcapture %}
<p class="post-meta">
<time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">{{ page.date | date: "%b %-d, %Y" }}</time> &bull;
{% if read_time != '0' %}
{{ read_time }}
{% else %}
1
{% endif %} min read
</p>
<h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
</header>

Expand Down
2 changes: 1 addition & 1 deletion blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1 class="page-heading">Blog</h1>
<div class="post-list">
{% for post in site.posts %}
<section>
<span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>
{% include post-meta.html %}

<div class="post-snippet">
<h2>{{ post.title }}</h2>
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ <h2>I make websites.</h2>
</section>
<section class="posts">
{% for post in site.posts limit:1 %}
<p class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</p>
<h2>{{ post.title }}</h2>
{% include post-meta.html %}
<h2>{{ post.title }}</h2>
{{ post.excerpt }}
<p class="buttons"><a href="{{ post.url | prepend: site.baseurl }}" class="button">read more</a> or <a href="/blog" class="button secondary">visit blog</a></p>
{% endfor %}
Expand Down

0 comments on commit 68ddaa3

Please sign in to comment.