Skip to content

Commit

Permalink
Added penultimate and index info to lists
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Apr 5, 2018
1 parent c859d6b commit 4a4021c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/render/load/list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
module.exports = function (list) {
list[0].first = true;
list[list.length -1].last = true;

if (list.length) {
list[list.length-1].last = true;
list[0].first = true;
}

if (list.length > 2) {
list[list.length-2].penultimate = true;
}

// Should I do a zero-based index or not?
// Decide before documenting this. Beware
// if you use this in your theme before then.
list = list.map(function(el, i){
el.index = i + 1;
return el;
});

return list;
}
};

0 comments on commit 4a4021c

Please sign in to comment.