Skip to content

Commit 10ec306

Browse files
committed
Fix collection reversing
1 parent 08d4254 commit 10ec306

File tree

8 files changed

+73
-47
lines changed

8 files changed

+73
-47
lines changed

.eleventy.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const fs = require('fs');
22
const pluginRss = require('@11ty/eleventy-plugin-rss');
33
const sassWatch = require('./_includes/sass-watch');
4-
const filterMarkdown = require('./_includes/filters/markdown');
5-
const filterRegexReplace = require('./_includes/filters/regex-replace');
4+
const filter = require('./_includes/filter');
65
const scAvatar = require('./_includes/shortcodes/avatar');
76
const scMeetupDetails = require('./_includes/shortcodes/meetup-details');
87
const scVideoPlayer = require('./_includes/shortcodes/video-player');
@@ -51,11 +50,14 @@ module.exports = (eleventyConfig) => {
5150
return addFileDates(posts);
5251
});
5352

53+
// FILTER: Reverse array without mutating original.
54+
eleventyConfig.addFilter('flip', filter.flip);
55+
5456
// FILTER: Run content thru Markdown-it.
55-
eleventyConfig.addFilter('markdown', filterMarkdown);
57+
eleventyConfig.addFilter('markdown', filter.markdown);
5658

5759
// FILTER: Replace text with regex capabilities.
58-
eleventyConfig.addFilter('regexReplace', filterRegexReplace);
60+
eleventyConfig.addFilter('regexReplace', filter.regexReplace);
5961

6062
// SHORTCODE: Format meeting details message block.
6163
eleventyConfig.addShortcode('meetupDetails', scMeetupDetails);

_includes/filter.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module.exports = {
2+
/**
3+
* Reverse array without mutating the original.
4+
* (The 'reverse' filter in LiquidJS v6 mutates the original array.)
5+
*
6+
* @param {Array} collection Array to be reversed.
7+
*
8+
* @return {Array} Reversed array.
9+
*/
10+
flip: (collection) => {
11+
if (!Array.isArray(collection)) return collection;
12+
13+
return [...collection].reverse();
14+
},
15+
16+
/**
17+
* Parse Markdown content to HTML.
18+
*
19+
* @param {string} content Incoming content (expecting Markdown).
20+
*
21+
* @return {string} Content rendered as HTML.
22+
*/
23+
markdown: (content) => {
24+
const md = require('markdown-it')({
25+
html: true,
26+
linkify: true,
27+
typographer: true,
28+
});
29+
30+
if (content) {
31+
return md.render(content);
32+
}
33+
34+
return '';
35+
},
36+
37+
/**
38+
* Allow regex in replace filter. Global flag set by default,
39+
*
40+
* @param {string} content Content to search/replace.
41+
* @param {string} rePattern RegExp patter to use.
42+
* @param {string} replacement Replacement text.
43+
* @return {string} Replaced content.
44+
*
45+
*/
46+
regexReplace: (content, rePattern, replacement) => {
47+
if (replacement === undefined || rePattern === undefined) return content;
48+
49+
const re = new RegExp(rePattern, 'g');
50+
51+
52+
return content.replace(re, replacement);
53+
},
54+
};

_includes/filters/markdown.js

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

_includes/filters/regex-replace.js

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

_includes/nav-posts.liquid

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<div class="columns is-variable is-8 has-offset-top">
22
<div class="column">
33
{%- if previousPost -%}
4-
<a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a>
4+
<a class="arrow-left" href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a>
55
{%- endif -%}
66
</div>
77

88
<div class="column has-text-right">
99
{%- if nextPost -%}
10-
<a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a>
10+
<a class="arrow-right" href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a>
1111
{%- endif -%}
1212
</div>
1313
</div>

_sass/_main.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ $footer-background-color: $white-ter;
246246
margin-bottom: -2rem;
247247
}
248248

249+
.arrow-left:before {
250+
content: '';
251+
}
252+
253+
.arrow-right:after {
254+
content: '';
255+
}
256+
249257
/*
250258
* THE REST
251259
*/

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ <h1 class="is-sr-only">{{ title }}</h1>
3131
<p>We work hard to build a community that treats people with excellence. We've formalized this in the <a href="{{ '/code-of-conduct/' | url }}">Austin JavaScript Code of Conduct</a>.</p>
3232
</section>
3333

34-
{%- assign meetups = collections.meetups | reverse -%}
3534
<section class="section">
3635
<h3>Past speakers and talks</h3>
37-
{%- for meetup in meetups -%}
36+
{%- for meetup in collections.meetups reversed -%}
3837
{%- for speaker in meetup.data.speakers -%}
3938
{%- if speaker.name and speaker.avatar -%}
4039
<figure class="pic">
@@ -53,6 +52,7 @@ <h3>Past speakers and talks</h3>
5352
<div class="content">
5453
<h3>Recent meetups</h3>
5554
<ul>
55+
{%- assign meetups = collections.meetups | flip -%}
5656
{%- for post in meetups limit: 5 -%}
5757
<li><a href="{{ post.url | url }}">{{ post.data.title }}</a></li>
5858
{%- endfor -%}

posts/meetups.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ <h1>{{ title }}</h1>
99
<p>{{ meta.description }}</p>
1010

1111
<ul>
12-
{%- assign meetups = collections.meetups -%}
13-
{%- for post in meetups -%}
12+
{%- for post in collections.meetups reversed -%}
1413
<li>
1514
<a href="{{ post.url | url }}">
1615
{{ post.inputPath | slice: 11, 10 }}:

0 commit comments

Comments
 (0)