The general idea is to take the built-in collection.all
, filter it down by the fileSlugs provided through the front matter and sort the filtered collection by their position in related
:
Create a custom filter in .eleventy.js
:
eleventyConfig.addFilter('filterRelated', (collection = [], related = []) => {
const filtered = collection.filter(page => related.includes(page.fileSlug));
return filtered.sort( (a, b) => related.indexOf(a.fileSlug) - related.indexOf(b.fileSlug));