Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Stable sort #215

Merged
merged 2 commits into from
Mar 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/create_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export default function create_routes({ files } = { files: glob.sync('**/*.*', {
}

if (!a_sub_part.dynamic && a_sub_part.content !== b_sub_part.content) {
return b_sub_part.content.length - a_sub_part.content.length;
return (
(b_sub_part.content.length - a_sub_part.content.length) ||
Copy link
Contributor

@thgh thgh Mar 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not only alphabetically?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a/b/foo.html needs to match before a/b/f[xx].html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I see now 😄 thank you!

(a_sub_part.content < b_sub_part.content ? -1 : 1)
);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
const rendered = route ? route.module.render({
status: statusCode,
error
}, {
store: store_getter && store_getter(req)
}) : { head: '', css: null, html: title };

const { head, css, html } = rendered;
Expand Down
43 changes: 41 additions & 2 deletions test/unit/create_routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('create_routes', () => {
[
'index.html',
'about.html',
'post/foo.html',
'post/bar.html',
'post/foo.html',
'post/f[xx].html',
'post/[id].json.js',
'post/[id].html',
Expand All @@ -23,7 +23,7 @@ describe('create_routes', () => {
});

it('prefers index page to nested route', () => {
const routes = create_routes({
let routes = create_routes({
files: [
'api/examples/[slug].js',
'api/examples/index.js',
Expand Down Expand Up @@ -55,6 +55,45 @@ describe('create_routes', () => {
'api/gists/[id].js',
]
);

routes = create_routes({
files: [
'4xx.html',
'5xx.html',
'api/blog/[slug].js',
'api/blog/index.js',
'api/guide/contents.js',
'api/guide/index.js',
'blog/[slug].html',
'blog/index.html',
'blog/rss.xml.js',
'gist/[id].js',
'gist/create.js',
'guide/index.html',
'index.html',
'repl/index.html'
]
});

assert.deepEqual(
routes.map(r => r.file),
[
'4xx.html',
'5xx.html',
'index.html',
'guide/index.html',
'blog/index.html',
'blog/rss.xml.js',
'blog/[slug].html',
'gist/create.js',
'gist/[id].js',
'repl/index.html',
'api/guide/index.js',
'api/guide/contents.js',
'api/blog/index.js',
'api/blog/[slug].js',
]
);
});

it('generates params', () => {
Expand Down