Skip to content

Commit

Permalink
feat: add reading time and word count
Browse files Browse the repository at this point in the history
Signed-off-by: Aaqa Ishtyaq <[email protected]>
  • Loading branch information
aaqaishtyaq committed Mar 7, 2024
1 parent 000c5cf commit 5429d5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 12 additions & 1 deletion sass/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,18 @@ p > code {

.date {
color: var(--fg4);
font-size: 14px;
font-size: 0.8750em;
}

.reading-time {
color: var(--fg4);
font-size: 0.8750em;
}

.page-meta {
display: flex;
justify-content: space-between;
align-items: center;
}

.border {
Expand Down
13 changes: 10 additions & 3 deletions templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
<div itemprop="headline">
<h1>{{ page.title }}</h1>
<div class="border"></div>
<time datetime="{{ page.date | date(format="%Y-%m-%d") }}" class="date" itemprop="datePublished">
{{ page.date | date(format="%d %b %Y") }}
</time>
<div class="page-meta">
<time datetime="{{ page.date | date(format=" %Y-%m-%d") }}" class="date" itemprop="datePublished">
{{ page.date | date(format="%d %b %Y") }}
</time>
<div class="reading-time">
{% set word_count = page.content | split(pat=" ") | length %}
{% set reading_time = (word_count / 250) | round %}
<div>{{ word_count }} words, {{ reading_time }} minutes to read</div>
</div>
</div>
</div>
<div itemprop="articleBody">
{{ page.content | safe }}
Expand Down

0 comments on commit 5429d5e

Please sign in to comment.