Skip to content

Commit beaebce

Browse files
committed
fix(#160): Use array to better sort editions.
1 parent 8b2d0ee commit beaebce

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

_src/_data/eleventyComputed.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default {
22
// Provide a structure by year to match expected output logic.
3-
years: function(data) {
3+
editions: function(data) {
44
const participants = data.participants;
5-
const years = {};
5+
const editions = [];
66
const yearMin = 2006; // The first CSS Naked Day.
77

88
let yearMax = yearMin;
@@ -11,30 +11,40 @@ export default {
1111
// Basic structure: year > participant > websites.
1212
participants[participant].websites.forEach(website => {
1313
website.years.forEach(year => {
14+
let currentEdition = editions.find(edition => edition.year === year);
15+
1416
yearMax = Math.max(yearMin, year);
1517

16-
if (!years[year]) {
17-
years[year] = {
18+
// Initialise year if it does not exist.
19+
if (!currentEdition) {
20+
editions.push({
21+
year: Number(year),
1822
'participants': {},
19-
};
23+
});
24+
25+
currentEdition = editions.find(edition => edition.year === year);
2026
}
2127

22-
if (!years[year]['participants'][participant]) {
23-
years[year]['participants'][participant] = [];
28+
// Populate participants for this year.
29+
if (!currentEdition['participants'][participant]) {
30+
currentEdition['participants'][participant] = [];
2431
}
2532

26-
years[year]['participants'][participant].push(website.url);
33+
// Populate participant with its websites for this year.
34+
currentEdition['participants'][participant].push(website.url);
2735
});
2836
});
2937
};
3038

31-
// Add missing years with no participant.
39+
// Add missing editions with no participant.
3240
for (let year = yearMin; year < yearMax; year++) {
33-
if (!years[year]) {
34-
years[year] = {};
41+
if (!editions.some((edition) => edition.year === year)) {
42+
editions.push({ year });
3543
}
3644
}
3745

38-
return years;
46+
editions.sort((a, b) => a.year > b.year ? 1 : -1);
47+
48+
return editions;
3949
}
4050
}

_src/index.njk

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@
4040
<h3><a id="editions" href="#editions">CSS Naked Day editions</a></h3>
4141

4242
<ul>
43-
44-
{% for index, year in years %}
43+
{% for edition in editions | reverse %}
4544
<li>
46-
{% if year.participants | length %}
47-
<a href="{{ index | slugify }}.html">{{ index }}</a>
45+
{% if edition.participants | length %}
46+
<a href="{{ edition.year | slugify }}.html">{{ edition.year }}</a>
4847
{% else %}
49-
{{ index }}
48+
{{ edition.year }}
5049
{% endif %}
5150
</li>
5251
{% endfor %}
53-
5452
</ul>
5553

5654
<h3><a id="participate" href="#participate">How to participate</a></h3>

_src/year.njk

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,37 @@
3636
<p>
3737
<a href="/">Home</a>
3838

39-
{% for index, year in years %}
40-
{% if year.participants | length %}
41-
· <a href="{{ index | slugify }}.html">{{ index }}</a>
39+
{% for edition in editions %}
40+
{% if edition.participants | length %}
41+
· <a href="{{ edition.year | slugify }}.html">{{ edition.year }}</a>
4242
{% else %}
43-
· {{ index }}
43+
· {{ edition.year }}
4444
{% endif %}
4545
{% endfor %}
4646
</p>
4747

4848
<h3>Kudos to these websites who got naked in {{ year }}!</h3>
4949

5050
<ol>
51-
{# We use both years and participants as Global Data. #}
52-
{% for index, websites in years[year].participants %}
53-
{% set participant = participants[index] %}
51+
{# We use both editions and participants as Global Data. #}
52+
{% for edition in editions %}
53+
{% if edition.year === year %}
54+
{% for filename, websites in edition.participants %}
55+
{% set participant = participants[filename] %}
5456

55-
<li>
56-
{%- if websites | length === 1 -%}
57-
{% linkNoSpam 'getParticipantDisplayName', websites[0], participant, year %}
58-
{%- else -%}
59-
{{ participant | getParticipantDisplayName }}:
57+
<li>
58+
{%- if websites | length === 1 -%}
59+
{% linkNoSpam 'getParticipantDisplayName', websites[0], participant, year %}
60+
{%- else -%}
61+
{{ participant | getParticipantDisplayName }}:
6062

61-
{% for website in websites -%}
62-
{% linkNoSpam 'getSiteTitle', website, participant, year, loop.index0 %}
63-
{%- endfor %}
64-
{% endif %}
65-
</li>
63+
{% for website in websites -%}
64+
{% linkNoSpam 'getSiteTitle', website, participant, year, loop.index0 %}
65+
{%- endfor %}
66+
{% endif %}
67+
</li>
68+
{% endfor %}
69+
{% endif %}
6670
{% endfor %}
6771
</ol>
6872

0 commit comments

Comments
 (0)