Skip to content

Commit cbe8201

Browse files
authored
Merge pull request #129 from stedman/avatar
Replace Nunjucks with LiquidJS, add avatar cache
2 parents 51c123e + 518d19d commit cbe8201

40 files changed

+718
-435
lines changed

.eleventy.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const fs = require('fs');
22
const pluginRss = require('@11ty/eleventy-plugin-rss');
33
const sassWatch = require('./_includes/sass-watch');
4-
const filterFullDate = require('./_includes/filters/full-date');
5-
const filterLimitTo = require('./_includes/filters/limit-to');
64
const filterMarkdown = require('./_includes/filters/markdown');
75
const filterRegexReplace = require('./_includes/filters/regex-replace');
6+
const scAvatar = require('./_includes/shortcodes/avatar');
87
const scMeetupDetails = require('./_includes/shortcodes/meetup-details');
98
const scVideoPlayer = require('./_includes/shortcodes/video-player');
109

@@ -52,12 +51,6 @@ module.exports = (eleventyConfig) => {
5251
return addFileDates(posts);
5352
});
5453

55-
// FILTER: Convert dates to MMMM D, YYYY format.
56-
eleventyConfig.addFilter('fullDate', filterFullDate);
57-
58-
// FILTER: Limit collection length.
59-
eleventyConfig.addFilter('limitTo', filterLimitTo);
60-
6154
// FILTER: Run content thru Markdown-it.
6255
eleventyConfig.addFilter('markdown', filterMarkdown);
6356

@@ -70,6 +63,9 @@ module.exports = (eleventyConfig) => {
7063
// SHORTCODE: Embed video players for event replay.
7164
eleventyConfig.addShortcode('videoPlayer', scVideoPlayer);
7265

66+
// SHORTCODE: Resize and cache images.
67+
eleventyConfig.addLiquidShortcode('avatar', scAvatar);
68+
7369
// PLUGIN: RSS feed
7470
eleventyConfig.addPlugin(pluginRss);
7571

@@ -98,12 +94,12 @@ module.exports = (eleventyConfig) => {
9894
layouts: './_layouts',
9995
},
10096
templateFormats: [
101-
'njk',
10297
'liquid',
98+
'njk',
10399
'md',
104100
'html',
105101
],
106-
htmlTemplateEngine: 'njk',
107-
dataTemplateEngine: 'njk',
102+
htmlTemplateEngine: 'liquid',
103+
dataTemplateEngine: 'liquid',
108104
};
109105
};

.eleventyignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
README.md
2+
CONTRIBUTING-POSTS.md
3+
_drafts/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
_site
1212
node_modules
1313
tmp
14+
.cache
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
<div class="media">
44
<div class="media-left">
55
<figure class="image is-96x96 has-background-grey-lighter">
6-
<img src="{{ person.avatar }}" alt="{{ person.name }}" loading="lazy">
6+
{%- avatar person.avatar, person.name -%}
77
</figure>
88
</div>
99
<div class="media-content">
1010
<p class="title is-size-5">{{ person.name }}</p>
1111
<p class="subtitle is-6 has-text-weight-semibold is-marginless-bottom">{{ person.title | markdown | safe }}</p>
1212
<div>
13-
{% include 'social-links.njk' %}
13+
{%- include social-links.liquid -%}
1414
</div>
1515
</div>
1616
</div>
1717
</div>
18-
{% if person.bio %}
18+
{%- if person.bio -%}
1919
<div class="card-footer">
2020
<div class="card-footer-item">
2121
<div class="content">
2222
{{ person.bio | markdown | safe }}
2323
</div>
2424
</div>
2525
</div>
26-
{% endif %}
26+
{%- endif -%}
2727
</div>

_includes/filters/full-date.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

_includes/filters/limit-to.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

_includes/filters/regex-replace.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*
99
*/
1010
module.exports = (content, rePattern, replacement) => {
11+
if (!(replacement && rePattern)) return content;
12+
1113
const re = new RegExp(rePattern, 'g');
1214

1315
return content.replace(re, replacement);

_includes/nav-posts.liquid

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div class="columns is-variable is-8 has-offset-top">
2+
<div class="column">
3+
{%- if previousPost -%}
4+
<a href="{{ previousPost.url | url }}">← {{ previousPost.data.title }}</a>
5+
{%- endif -%}
6+
</div>
7+
8+
<div class="column has-text-right">
9+
{%- if nextPost -%}
10+
<a href="{{ nextPost.url | url }}">{{ nextPost.data.title }} →</a>
11+
{%- endif -%}
12+
</div>
13+
</div>

_includes/shortcodes/avatar.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Image = require('@11ty/eleventy-img');
2+
3+
module.exports = async (src, alt, className, outputFormat = 'jpeg') => {
4+
const stats = await Image(src, {
5+
cacheDuration: '12w',
6+
formats: [outputFormat],
7+
outputDir: '_site/assets/avatar/',
8+
widths: [96],
9+
});
10+
11+
const classAttr = className ? `class="${className}"` : '';
12+
13+
const props = stats[outputFormat].pop();
14+
15+
if (alt === undefined) {
16+
throw new Error(`Missing ALT attribute from: ${src}`);
17+
}
18+
19+
return `<img ${classAttr} src="${props.outputPath.replace('_site', '')}" alt="${alt}" loading="lazy">`;
20+
};

_includes/shortcodes/meetup-details.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
const organizations = require('../../_data/organizations.json');
22
const siteData = require('../../_data/site.json');
3-
const filterFullDate = require('../filters/full-date');
3+
4+
/**
5+
* Filter date output to follow pattern MMMM D, YYYY
6+
*
7+
* @param {object} dateValue Date object
8+
*
9+
* @return {string} Formatted date string.
10+
*/
11+
const fullDate = (dateValue) => {
12+
const monthNames = [
13+
'January', 'February', 'March', 'April', 'May', 'June',
14+
'July', 'August', 'September', 'October', 'November', 'December',
15+
];
16+
const newDate = new Date(dateValue);
17+
18+
return `${monthNames[newDate.getMonth()]} ${newDate.getDate()}, ${newDate.getFullYear()}`;
19+
};
420

521
/**
622
* Provide template for meeting details.
@@ -58,7 +74,7 @@ module.exports = function meetupDetails(meetDate, venue, after, msgHeader, meetT
5874
<span class="icon has-text-grey-dark">
5975
<ion-icon src="/assets/ionicon/calendar.svg"></ion-icon>
6076
</span>
61-
<time class="has-text-primary has-text-weight-bold" dateTime="${meetDate.toISOString().substring(0, 10)}">${filterFullDate(meetDate)}</time>
77+
<time class="has-text-primary has-text-weight-bold" dateTime="${meetDate.toISOString().substring(0, 10)}">${fullDate(meetDate)}</time>
6278
</div>
6379
6480
<div>

0 commit comments

Comments
 (0)