Skip to content

Commit 93f4115

Browse files
committed
Sort glossary alphabetically by term
1 parent 019327f commit 93f4115

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.eleventy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ module.exports = function(eleventyConfig) {
103103
return yaml.safeDump(obj)
104104
});
105105

106+
// sort an array of objects by one object key value
107+
eleventyConfig.addFilter('sortKey', (arr, key) => {
108+
return arr.sort((a, b) => {
109+
let aKey = a[key].toLowerCase();
110+
let bKey = b[key].toLowerCase();
111+
if(aKey < bKey) {
112+
return -1;
113+
} else if(aKey > bKey) {
114+
return 1;
115+
}
116+
return 0;
117+
})
118+
})
119+
106120
// favicons files
107121
eleventyConfig.addPassthroughCopy("src/site/browserconfig.xml");
108122
eleventyConfig.addPassthroughCopy("src/site/site.webmanifest");

src/site/glossary.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ layout: layouts/base.njk
1212

1313
<section class="no-underline">
1414
<ul>
15-
{% for item in glossary | selectattr("definition") %}
15+
{% for item in glossary | selectattr("definition") | sortKey("term") %}
1616
<li class="my-2"><a href="/glossary/{{ item.id }}">{{ item.term }}</a></li>
1717
{% endfor %}
1818
</ul>

0 commit comments

Comments
 (0)