Skip to content

Commit

Permalink
Merge pull request #38 from mainmatter/pichfl/use-natural-sort
Browse files Browse the repository at this point in the history
Use localeCompare instead of custom regex
  • Loading branch information
pichfl authored Sep 12, 2024
2 parents ed779eb + 56f2c28 commit 38b145a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ const markdownFiles = import.meta.glob('slides/*.md', {
eager: true,
});

const sortedMarkdownFiles = Object.entries(markdownFiles).sort(([a], [b]) => {
const regex = /slides\/(\d+)-/;
const [, aNumb] = regex.exec(a);
const [, bNumb] = regex.exec(b);

return Number(aNumb) - Number(bNumb);
});
const sortedMarkdownFiles = Object.entries(markdownFiles).sort(([a], [b]) =>
a.localeCompare(b, undefined, {
numeric: true,
sensitivity: 'base',
}),
);

const sections = sortedMarkdownFiles.map(
([, content]) => `
Expand Down

0 comments on commit 38b145a

Please sign in to comment.