Skip to content

Commit 86cabe9

Browse files
committed
feat: add Eleventy configuration and role template partials
- Update .eleventy.js with role filtering functions (byRole, byAnyRole) - Add role-group-sections.njk partial for displaying role groups - Add role-mini-toc.njk partial for role navigation - Enable role-based content filtering across the site
1 parent a83c32f commit 86cabe9

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

.eleventy.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,45 @@ module.exports = function (eleventyConfig) {
195195
return changedPages; // Returning the changed URLs, titles, and locales for the template
196196
});
197197

198+
// Get the role keys that belong to a given group
199+
eleventyConfig.addFilter("roleKeysForGroup", function (groupKey, rolesData) {
200+
if (!groupKey || !rolesData || !rolesData.roles) return [];
201+
return Object.entries(rolesData.roles)
202+
.filter(([, meta]) => meta.group === groupKey)
203+
.map(([key]) => key);
204+
});
205+
206+
// Given a list of role keys, return all pages that match ANY of them
207+
eleventyConfig.addFilter("byAnyRole", function (collection, roleKeys) {
208+
if (!collection || !roleKeys || !roleKeys.length) return [];
209+
return collection.filter((item) => {
210+
const r = item.data.role;
211+
if (!r) return false;
212+
const arr = Array.isArray(r) ? r : [r];
213+
return arr.some((k) => roleKeys.includes(k));
214+
});
215+
});
216+
217+
// Collection of all pages that have at least one role
218+
eleventyConfig.addCollection("rolePages", (api) =>
219+
api.getAll().filter((item) => !!item.data.role)
220+
);
221+
222+
// Custom collection for role groups to work around pagination tag issues
223+
eleventyConfig.addCollection("roleGroup", (api) => {
224+
// Find all pages generated from the roles-group.njk template OR
225+
// pages with URLs matching role group patterns
226+
return api.getAll().filter((item) => {
227+
// Check if the page was generated from the roles-group template
228+
const fromRoleGroupTemplate = item.inputPath && item.inputPath.includes('roles-group.njk');
229+
230+
// Check if URL matches role group pattern (e.g., /en/roles/business/, /fr/roles/design/)
231+
const matchesRoleGroupPattern = item.url && item.url.match(/^\/(en|fr)\/roles\/(administration|author|business|design|development|testing)\/$/);
232+
233+
return fromRoleGroupTemplate || matchesRoleGroupPattern;
234+
});
235+
});
236+
198237
// Add custom Markdown filter for Nunjucks
199238
eleventyConfig.addNunjucksFilter("markdown", function (value) {
200239
return md.render(value);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{# expects: lang, locale, rolesData, groupRoleKeys, collections, pathPrefix, landingPage, alerts #}
2+
{% for rk in groupRoleKeys %}
3+
{% set label = rolesData.labels[lang][rk] or rk %}
4+
{% set anchor = label | stripTagsSlugify %}
5+
{% set items = collections.rolePages
6+
| byAnyRole([rk])
7+
| localeMatch(locale)
8+
| sort(false, false, 'data.title') %}
9+
10+
{% if items.length %}
11+
<section class="mrgn-bttm-xl">
12+
<h2 id="{{ anchor }}">{{ label }}</h2>
13+
<p><a href="{{ pathPrefix }}{{ permalinkPrefix }}{{ locale }}/roles/{{ rk }}/">{% if lang == 'fr' %}Aller à la page {{ label | lower }} <small class="text-muted">({{ items.length }})</small>{% else %}Go to {{ label | lower }} page <small class="text-muted">({{ items.length }})</small>{% endif %}</a></p>
14+
<div class="row wb-eqht mrgn-tp-lg gc-drmt">
15+
{% for item in items %}
16+
<div class="col-md-6">
17+
<h3 class="h4">
18+
<a{% if item.data.redirect %} rel="external" {% endif %}
19+
href="{% if item.data.redirect %}{{ item.data.redirect }}{% else %}{{ pathPrefix }}{{ item.url }}{% endif %}"
20+
{% if item.data.oneLanguage %} hreflang="{{ landingPage[locale].otherLang }}" {% endif %}>
21+
{% if item.data.internal === true %}
22+
<span class="fas fa-external-link-square-alt mrgn-lft-sm mrgn-rght-sm" aria-hidden="true"></span>
23+
<span class="wb-inv"> {{ alerts[locale].hiddenTextLink }}</span>
24+
{% endif %}
25+
{{ item.data.title | safe }}
26+
{% if item.data.oneLanguage %}<small> {{ landingPage[locale].otherLangOnly }}</small>{% endif %}
27+
</a>
28+
</h3>
29+
<p>
30+
{% if item.data.description %}
31+
{{ item.data.description | safe }}
32+
{% else %}
33+
{{ landingPage[locale].descriptionNoneText }}
34+
{% endif %}
35+
</p>
36+
</div>
37+
{% endfor %}
38+
</div>
39+
</section>
40+
{% endif %}
41+
{% endfor %}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{# expects: lang, locale, rolesData, groupRoleKeys, collections #}
2+
<aside>
3+
<h2>{{ onThisPage[locale].heading }}</h2>
4+
<ul class="mrgn-bttm-lg">
5+
{% for rk in groupRoleKeys %}
6+
{% set label = rolesData.labels[lang][rk] or rk %}
7+
{% set anchor = label | stripTagsSlugify %}
8+
{% set items = collections.rolePages
9+
| byAnyRole([rk])
10+
| localeMatch(locale)
11+
| sort(false, false, 'data.title') %}
12+
{% if items.length %}
13+
<li class="list-inline-item">
14+
<a href="#{{ anchor }}">{{ label }}</a>
15+
<small class="text-muted">({{ items.length }})</small>
16+
</li>
17+
{% endif %}
18+
{% endfor %}
19+
</ul>
20+
</aside>

0 commit comments

Comments
 (0)