Skip to content

Commit 6888d43

Browse files
committed
Add optional read time
1 parent c925877 commit 6888d43

File tree

11 files changed

+88
-24
lines changed

11 files changed

+88
-24
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ insert_final_newline = true
1111

1212
[*.md]
1313
trim_trailing_whitespace = false
14+
15+
[*.svg]
16+
trim_trailing_whitespace = false

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Basically Basic is a [Jekyll theme](https://jekyllrb.com/docs/themes/) meant as
2121
4. [Navigation](#navigation)
2222
5. [Pagination](#pagination)
2323
6. [Author](#author)
24-
7. [Comments (via Disqus)](#comments-via-disqus)
24+
7. [Reading Time](#reading-time)
25+
8. [Comments (via Disqus)](#comments-via-disqus)
26+
9. [Google Analytics](#google-analytics)
2527
3. [Layouts](#layouts)
2628
1. [Default](#layout-default)
2729
2. [Post](#layout-post)
@@ -103,6 +105,7 @@ t:
103105
posts: "Posts"
104106
page: "Page"
105107
of: "of"
108+
min_read: "min read"
106109
```
107110

108111
### Navigation
@@ -184,6 +187,10 @@ drlight:
184187

185188
Currently `author.picture` is only used in `layout: about`. Recommended size is `300 x 300` pixels.
186189

190+
### Reading Time
191+
192+
To enable reading time counts add `read_time: true` to a post or page's YAML Front Matter.
193+
187194
### Comments (via Disqus)
188195

189196
Optionally, if you have a [Disqus](https://disqus.com/) account, you can show a comments section below each post.

_data/theme.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ t:
1616
posts: "Posts"
1717
page: "Page"
1818
of: "of"
19+
min_read: "min read"
1920

2021
# Google Fonts
2122
google_fonts:
@@ -28,4 +29,4 @@ google_fonts:
2829

2930
navigation_pages:
3031
- about.md
31-
- cv.md
32+
- cv.md

_includes/entry.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
<h3 class="entry-title">
1010
<a href="{{ post.url | relative_url }}" rel="bookmark">{{ title }}</a>
1111
</h3>
12-
<p class="entry-meta">
13-
{% if post.date %}
14-
<time class="entry-time" datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: "%B %-d, %Y" }}</time>
15-
{% endif %}
16-
</p>
1712
</header>
13+
<footer class="entry-meta">
14+
<ul>
15+
{% if post.date %}
16+
<li><span class="icon">{% include icon-calendar.svg %}</span><time class="entry-time" datetime="{{ post.date | date_to_xmlschema }}">{{ post.date | date: "%B %-d, %Y" }}</time></li>
17+
{% endif %}
18+
{% if post.read_time %}
19+
<li><span class="icon">{% include icon-stopwatch.svg %}</span>{% capture read_time %}{% include read-time.html %}{% endcapture %}{{ read_time | strip }}</li>
20+
{% endif %}
21+
</ul>
22+
</footer>
1823
<div class="entry-excerpt">
1924
{% if post.excerpt %}
2025
{{ post.excerpt | markdownify }}
2126
<p><a href="{{ post.url | relative_url }}" class="more-link">{{ site.data.theme.t.read_more | default: 'Read More' }} <span class="icon icon--arrow-right">{% include icon-arrow-right.svg %}</span></a></p>
2227
{% endif %}
2328
</div>
24-
</article>
29+
</article>

_includes/icon-calendar.svg

Lines changed: 1 addition & 0 deletions
Loading

_includes/page-intro.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h1 class="intro-title">{{ page.alt_title | default: page.title | default: site.
2020
{% if page.date %}
2121
{% include author %}
2222
<p class="entry-meta">
23-
{% if author_name %}<span class="byline-item">{{ author_name | prepend: 'by ' }}</span>{% endif %}<span class="byline-item"><time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %-d, %Y" }}</time></span>
23+
{% if author_name %}<span class="byline-item">{{ author_name | prepend: 'by ' }}</span>{% endif %}<span class="byline-item"><span class="icon">{% include icon-calendar.svg %}</span><time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %-d, %Y" }}</time></span>{% if page.read_time %} <span class="byline-item"><span class="icon">{% include icon-stopwatch.svg %}</span>{% capture read_time %}{% include read-time.html %}{% endcapture %}{{ read_time | strip }}</span>{% endif %}
2424
</p>
2525
{% endif %}
2626

_includes/read-time.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% assign words_per_minute = site.words_per_minute | default: 200 %}
2+
3+
{% if post.read_time %}
4+
{% assign words = post.content | strip_html | number_of_words %}
5+
{% elsif page.read_time %}
6+
{% assign words = page.content | strip_html | number_of_words %}
7+
{% endif %}
8+
9+
{% if words < words_per_minute %}
10+
~1 {{ site.data.theme.t.min_read | default: 'min read' }}
11+
{% else %}
12+
{{ words | divided_by:words_per_minute }} {{ site.data.theme.t.min_read | default: 'min read' }}
13+
{% endif %}

_sass/basically-basic/_entries.scss

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@
3737

3838
.byline-item {
3939

40-
&:not(:first-child)::before {
41-
margin: 0 0.5em;
42-
content: '\00b7';
40+
&:not(:first-child) {
41+
margin-left: 1.5rem;
4342
}
4443
}
44+
45+
.icon {
46+
margin-right: 0.5em;
47+
fill: $accent-color;
48+
}
4549
}
4650

4751
/*
@@ -53,24 +57,28 @@
5357
.entry-header {
5458

5559
@include breakpoint($medium) {
56-
@include span(5 of 16);
57-
@include suffix(1 of 16);
60+
// @include span(5 of 16);
61+
// @include suffix(1 of 16);
5862

5963
/* remove space after last child element */
60-
> *:last-child {
61-
margin-bottom: 0;
62-
}
64+
// > *:last-child {
65+
// margin-bottom: 0;
66+
// }
6367
}
6468
}
6569

66-
/* break long words that could overflow */
70+
6771
.entry-title {
68-
word-wrap: break-word;
72+
word-wrap: break-word; /* break long words that could overflow */
73+
74+
a:hover {
75+
color: $accent-color;
76+
}
6977
}
7078

7179
.entry-excerpt {
7280
@include breakpoint($medium) {
73-
@include span(11 of 16 last);
81+
@include span(11 of 16);
7482
}
7583

7684
/* normalize font sizes */
@@ -86,14 +94,38 @@
8694

8795
.entry-content {
8896
@include breakpoint($medium) {
89-
@include span(11 of 16 last);
97+
@include span(11 of 16);
9098
}
9199

92100
/* remove space after last child element */
93101
> *:last-child {
94102
margin-bottom: 0;
95103
}
96104
}
105+
106+
.entry-meta {
107+
@include breakpoint($medium) {
108+
@include span(5 of 16 last);
109+
@include prefix(1 of 16);
110+
}
111+
112+
ul {
113+
@include list-unstyled();
114+
115+
@include breakpoint(max-width $medium) {
116+
li {
117+
display: inline-block;
118+
margin-right: 1.5rem;
119+
}
120+
}
121+
122+
@include breakpoint($medium) {
123+
li {
124+
padding-bottom: 0.5rem;
125+
}
126+
}
127+
}
128+
}
97129
}
98130

99131
.entry-content {

_sass/basically-basic/_intro.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
.intro-image {
1212
position: relative;
1313
margin-top: -3rem; /* compensate for intro top margin */
14-
margin-bottom: 2rem;
14+
margin-bottom: 3rem;
1515

1616
&::before {
1717
position: absolute;

example/_config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ defaults:
6464
path: "_posts"
6565
type: posts
6666
values:
67-
layout: post
67+
layout: post
68+
read_time: true

0 commit comments

Comments
 (0)