File tree Expand file tree Collapse file tree 4 files changed +25
-7
lines changed
Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Original file line number Diff line number Diff line change 1+ const lodashGet = require ( "lodash/get" ) ;
12
23module . exports = function ( eleventyConfig ) {
34
@@ -104,18 +105,34 @@ module.exports = function(eleventyConfig) {
104105 } ) ;
105106
106107 // sort an array of objects by one object key value
107- eleventyConfig . addFilter ( 'sortKey' , ( arr , key ) => {
108+ // can also get fancy and do a lodash.get selector string too
109+ // see https://lodash.com/docs/4.17.15#get
110+ eleventyConfig . addFilter ( 'sortKey' , ( arr , selector ) => {
108111 return arr . sort ( ( a , b ) => {
109- let aKey = a [ key ] . toLowerCase ( ) ;
110- let bKey = b [ key ] . toLowerCase ( ) ;
112+ let aKey = lodashGet ( a , selector ) . toLowerCase ( ) ;
113+ let bKey = lodashGet ( b , selector ) . toLowerCase ( ) ;
111114 if ( aKey < bKey ) {
112115 return - 1 ;
113116 } else if ( aKey > bKey ) {
114117 return 1 ;
115118 }
116119 return 0 ;
117- } )
118- } )
120+ } ) ;
121+ } ) ;
122+
123+ eleventyConfig . addFilter ( 'sortTools' , ( arr , githubData ) => {
124+ return arr . sort ( ( a , b ) => {
125+ let aKey = githubData [ a . data . repo ] ? ( githubData [ a . data . repo ] . stars || 0 ) : 0 ;
126+ let bKey = githubData [ b . data . repo ] ? ( githubData [ b . data . repo ] . stars || 0 ) : 0 ;
127+ if ( aKey < bKey ) {
128+ return 1 ;
129+ } else if ( aKey > bKey ) {
130+ return - 1 ;
131+ }
132+ return 0 ;
133+ } ) ;
134+ } ) ;
135+
119136
120137 // favicons files
121138 eleventyConfig . addPassthroughCopy ( "src/site/browserconfig.xml" ) ;
Original file line number Diff line number Diff line change 2828 "fast-glob" : " ^3.2.4" ,
2929 "gray-matter" : " ^4.0.2" ,
3030 "js-yaml" : " ^3.13.1" ,
31+ "lodash" : " ^4.17.20" ,
3132 "luxon" : " ^1.23.0" ,
3233 "markdown-it" : " ^11.0.1" ,
3334 "netlify-plugin-minify-html" : " ^0.2.2" ,
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ layout: layouts/base.njk
1414
1515<section class =" cards mt-12" >
1616 <div class =" grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-3" >
17- {% for item in collections .generators %}
17+ {% for item in collections .generators | sortTools ( github ) %}
1818 {{ cards .repo (item , loop .index0 , github ) }}
1919 {% endfor %}
2020 </div >
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ layout: layouts/base.njk
1414
1515<section class =" cards mt-12" >
1616 <div class =" grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-3" >
17- {% for item in collections .cms %}
17+ {% for item in collections .cms | sortTools ( github ) %}
1818 {{ cards .repo (item , loop .index0 , github ) }}
1919 {% endfor %}
2020 </div >
You can’t perform that action at this time.
0 commit comments