order |
---|
1 |
Last active
August 20, 2018 19:35
-
-
Save Andy-set-studio/47f4dd9cd0adc0ab50c91948c51e2892 to your computer and use it in GitHub Desktop.
Eleventy sort by order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sortByOrder = require('./sort-by-order.js'); | |
module.exports = function(eleventyConfig) { | |
eleventyConfig.addFilter('sortByOrder', sortByOrder); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return back an array of collection items in the correct order that's set by the `order` front-matter. | |
* | |
* @param {array} value | |
* @returns {array} | |
*/ | |
module.exports = function sortByOrder(value) { | |
return value.sort((a, b) => { | |
return parseInt(a.data.order, 10) - parseInt(b.data.order, 10); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for item in collections.all | sortByOrder %} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment