Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time to read #74

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/assets/styles/components/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
margin: 0;
font-weight: 500;
font-style: italic;
border-left: 4px solid var(--text-primary);
border-left: 3px solid var(--text-primary);
padding-left: 1em;
margin: 2.75rem -1.5rem;

Expand Down
10 changes: 8 additions & 2 deletions src/assets/styles/components/writing/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
&--content {
margin: 144px 0px 0px 0px;
padding-bottom: 64px;

border-bottom: 1px solid var(--border-default);

@include mq-down(lg) {
Expand All @@ -14,8 +13,15 @@
padding-bottom: 44px;
}

.info {
display: flex;
gap: 8px;
color: var(--text-secondary);
margin-top: 24px;
}

h1 {
margin: 24px 0px;
margin: 0px 0px 24px 0px;
}
}
}
15 changes: 12 additions & 3 deletions src/includes/writing/header.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
>
<div class="writing-detail--content">
<div class="title">
<p>
{{ page.date | dateToFormat('DDD') }}
</p>

<h1>{{title}}</h1>

<p class="subtitle">
{{ description }}
</p>

<div class="info">
<p>
{{ page.date | dateToFormat('DDD') }}
</p>
<div>
<span aria-hidden="true">·</span>
</div>
<div>
<span aria-hidden="true">{{ content | readingTime }}</span>
</div>
</div>
</div>
</div>
</r-cell>
8 changes: 8 additions & 0 deletions utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@ module.exports = {
return collection.filter(
(item) => item.data.tags && item.data.tags.includes(tag)
)
},

readingTime: function (content) {
const WPM = 200

const wordCount = content.split(/\s+/).length
const readingTime = Math.ceil(wordCount / WPM)
return `${readingTime} min${readingTime !== 1 ? "s" : ""} read`
}
}