Skip to content

Commit

Permalink
customization : add reading time
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainmetayer committed Feb 16, 2022
1 parent 08d9a85 commit 242a611
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 231 deletions.
9 changes: 9 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const emojiReadTime = require("@11tyrocks/eleventy-plugin-emoji-readtime");
const markdownConfig = require('./src/11ty/utils/markdown');
const browserSyncConfig = require('./src/11ty/utils/browsersync');
const UserConfig = require("@11ty/eleventy/src/UserConfig");
Expand Down Expand Up @@ -30,11 +31,19 @@ module.exports = function (eleventyConfig) {
});

eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(emojiReadTime, {
emoji: "🍿",
label: "min.",
wpm: 250,
bucketSize: 3,
});

passthroughItems.forEach(item => {
eleventyConfig.addPassthroughCopy(item);
})

eleventyConfig.addWatchTarget("./src/scss/*.scss");

eleventyConfig.setBrowserSyncConfig(browserSyncConfig);
eleventyConfig.setLibrary("md", markdownConfig);
eleventyConfig.setDataDeepMerge(true);
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"@11ty/eleventy": "^1.0.0",
"@11ty/eleventy-navigation": "^0.3.2",
"@11tyrocks/eleventy-plugin-emoji-readtime": "^1.0.1",
"autoprefixer": "^10.4.2",
"beautify": "^0.0.8",
"html-validate": "^6.3.1",
Expand Down
5 changes: 0 additions & 5 deletions src/_data/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
module.exports = {
getReadingTime(text) {
const wordsPerMinute = 200;
const numberOfWords = text.split(/\s/g).length;
return Math.ceil(numberOfWords / wordsPerMinute);
},
url() {
// TODO Nunjucks configure access to process.env
if (typeof process === 'undefined') {
Expand Down
4 changes: 1 addition & 3 deletions src/_data/home.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"title": "Bonjour, je suis Sylvain",
"image": "/static/img/profile.png",
"subtitle": "Développeur web à Bordeaux, vous trouverez ici mes articles et projets.",
"image_alt": "Avatar de Sylvain"
"subtitle": "Développeur web à Bordeaux, vous trouverez ici mes articles et projets."
}
208 changes: 0 additions & 208 deletions src/_includes/assets/css/base-styles.css

This file was deleted.

2 changes: 1 addition & 1 deletion src/_includes/assets/css/blog.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
border-radius: var(--border-radius-sm);
color: var(--color-secondary);
white-space: nowrap;
font-size: 13px;
font-size: 15px;
font-weight: 500;
}

Expand Down
2 changes: 1 addition & 1 deletion src/_includes/assets/css/home-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

@media (min-width: 1024px) {
.hero__title {
font-size: 3.3em;
font-size: 3em;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/_includes/assets/css/site-header.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
.site-header__item {
margin: 0 6px;
font-weight: 500;
font-size: 14px;
font-size: 17px;
}

@media (min-width: 1024px) {
.site-header__item {
margin: 0 20px;
font-size: 15px;
font-size: 17px;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/_includes/assets/css/utilites.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
border-radius: var(--border-radius-sm);
background-color: var(--color-secondary);
color: var(--color-text-alt);
font-size: 14px;
font-size: 15px;
white-space: nowrap;
}

Expand Down
7 changes: 4 additions & 3 deletions src/_includes/components/postslist.njk
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
</a>
</h5>
{% if post.data.date %}
{{ post.data.date | date }}
{{ post.data.date | date }}
{% endif %}
{% if post._templateContent %}
<span>{{ post._templateContent | emojiReadTime }} de lecture</span>
{% endif %}
{% set readingTime = helpers.getReadingTime(post._templateContent) -%}
<span>— Temps de lecture: {{ readingTime }} minute{% if readingTime > 1 %}s{% endif %}</span>
{% if post.data.excerpt %}
<p class="article-card__summary">
{{ post.data.excerpt }}
Expand Down
8 changes: 7 additions & 1 deletion src/_includes/components/projectlist.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
{% endif %}
</a>
</h4>
{% if post.data.date %}
{{ post.data.date | date }}
{% endif %}
{% if post._templateContent %}
<span>{{ post._templateContent | emojiReadTime }} de lecture</span>
{% endif %}
{% if post.data.summary %}
<p>
{{ post.data.summary }}
Expand All @@ -30,7 +36,7 @@
</p>
{% endif %}
</div>
{% endif %}
{% endif %}
{% endfor %}
</div>
</section>
9 changes: 6 additions & 3 deletions src/_includes/layouts/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ section: post
<article>
<h1>{{ title }}</h1>
<p>
<small>
<time datetime="{{ date | machineDate }}">{{ date | date }}</time>
</small>
<time datetime="{{ date | machineDate }}">{{ date | date }}</time> par {{ author }}
</p>
{% if layoutContent %}
<p>
{{ layoutContent | emojiReadTime }} de lecture
</p>
{% endif %}
<hr>

{{ layoutContent | safe }}
Expand Down
Loading

0 comments on commit 242a611

Please sign in to comment.