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.
|
// Fix page sorting. By default this is by file created date? We want it to be by filename.
|
||||||
eleventyConfig.addCollection('pages', (collection) => (collection
|
eleventyConfig.addCollection('pages', (collection) => {
|
||||||
.getFilteredByGlob(['site-source/index.md', 'site-source/page-*.md'])
|
const comparator = Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
|
||||||
.map(page => {
|
const compareSlugs = (a, b) => comparator.compare(a.fileSlug, b.fileSlug);
|
||||||
let number;
|
return collection.getFilteredByTag('pages').sort(compareSlugs);
|
||||||
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)
|
|
||||||
));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
markdownTemplateEngine: 'njk',
|
markdownTemplateEngine: 'njk',
|
||||||
|
|
Loading…
Add table
Reference in a new issue