turns out that sorting algorithm is already in the standard library
This commit is contained in:
parent
f9460a27c9
commit
8242e4aee0
1 changed files with 5 additions and 14 deletions
|
@ -22,20 +22,11 @@ export default function(eleventyConfig) {
|
|||
});
|
||||
|
||||
// Fix page sorting. By default this is by file created date? We want it to be by filename.
|
||||
eleventyConfig.addCollection('pages', (collection) => (collection
|
||||
.getFilteredByGlob(['site-source/index.md', 'site-source/page-*.md'])
|
||||
.map(page => {
|
||||
let number;
|
||||
if (page.fileSlug == 'index') {
|
||||
number = 0;
|
||||
} else {
|
||||
number = Number(page.fileSlug.slice('page-'.length));
|
||||
}
|
||||
return { page, number };
|
||||
})
|
||||
.sort((a, b) => a.number - b.number)
|
||||
.map(p => p.page)
|
||||
));
|
||||
eleventyConfig.addCollection('pages', (collection) => {
|
||||
const comparator = Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
|
||||
const compareSlugs = (a, b) => comparator.compare(a.fileSlug, b.fileSlug);
|
||||
return collection.getFilteredByTag('pages').sort(compareSlugs);
|
||||
});
|
||||
|
||||
return {
|
||||
markdownTemplateEngine: 'njk',
|
||||
|
|
Loading…
Add table
Reference in a new issue