Skip to content

Commit 257ff22

Browse files
committed
feat: Allow prefix and suffix for each website…
This allows to compose the output, by year if necessary.
1 parent 2d3adcc commit 257ff22

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

_src/_data/participants/tom-hazledine.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ display = "Tom Hazledine"
66
[[websites]]
77
url = "https://tomhazledine.com/"
88
years = [2020,2024,2025]
9-
years = [2020,2024]
9+
suffix = ''
1010

1111
[[websites]]
1212
url = "https://tomhazledine.com/css-naked-day/"
1313
title = "always naked"
1414
years = [2024,2025]
15+
prefix = " (some of which is "
16+
suffix = ")"

_src/year.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353

5454
<li>
5555
{% if websites | length === 1 %}
56-
{% linkNoSpam 'getParticipantDisplayName', websites[0], participant %}
56+
{% linkNoSpam 'getParticipantDisplayName', websites[0], participant, year %}
5757
{% else %}
5858
{{ participant | getParticipantDisplayName }}:
5959

6060
{% for website in websites %}
61-
{% linkNoSpam 'getSiteTitle', website, participant %}{% if loop.revindex0 > 1 %}, {% endif %}{% if loop.revindex0 === 1 %} & {% endif %}
61+
{% linkNoSpam 'getSiteTitle', website, participant, year, loop.revindex0 %}
6262
{% endfor %}
6363
{% endif %}
6464
</li>

eleventy.config.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,25 @@ export default function (eleventyConfig) {
3333
return website.title || getWebsiteDomain(website.url);
3434
});
3535

36-
eleventyConfig.addFilter("getSiteData", (url, participant) => {
36+
// Return website matching url and year.
37+
// This allows to have different configurations for different years.
38+
// This is uSeful for prefix and suffix which might need different values depending on the year.
39+
eleventyConfig.addFilter("getSiteData", (url, participant, year) => {
3740
return participant.websites.find(website => {
38-
return website.url === url;
41+
return website.url === url && website.years.includes(year);
3942
});
4043
});
4144

42-
eleventyConfig.addShortcode("linkNoSpam", function(callback, url, participant) {
43-
const website = eleventyConfig.getFilter("getSiteData")(url, participant);
45+
eleventyConfig.addShortcode("linkNoSpam", function(callback, url, participant, year, loopRevIndex0) {
46+
const website = eleventyConfig.getFilter("getSiteData")(url, participant, year);
47+
48+
if(!website) {
49+
return;
50+
};
51+
4452
let title;
53+
let prefix = website.prefix;
54+
let suffix = website.suffix;
4555

4656
switch (callback) {
4757
case 'getSiteTitle':
@@ -52,6 +62,10 @@ export default function (eleventyConfig) {
5262
break;
5363
}
5464

65+
if (suffix === undefined && loopRevIndex0) {
66+
suffix = loopRevIndex0 > 1 ? ', ' : ' & ';
67+
}
68+
5569
if (!website?.url) {
5670
return title;
5771
}
@@ -60,7 +74,7 @@ export default function (eleventyConfig) {
6074
return website.url;
6175
}
6276

63-
return `<a href="${website.url}">${title}</a>`
77+
return `${prefix || ''}<a href="${website.url}">${title}</a>${suffix || ''}`
6478
});
6579

6680
// TODO: Add a tool to target duplicated domains.

0 commit comments

Comments
 (0)