File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff 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" ) ;
Original file line number Diff line number Diff 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 >
You can’t perform that action at this time.
0 commit comments