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

Commit bdd5a54

Browse files
authored
Merge pull request #301 from sveltejs/gh-297
treat foo/index.json.js as foo.json.js
2 parents 5b5f33d + b7bb4db commit bdd5a54

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/core/create_routes.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export default function create_routes({ files } = { files: glob.sync('**/*.*', {
1717

1818
const base = file.replace(/\.[^/.]+$/, '');
1919
const parts = base.split('/'); // glob output is always posix-style
20-
if (parts[parts.length - 1] === 'index') parts.pop();
20+
if (/^index(\..+)?/.test(parts[parts.length - 1])) {
21+
const part = parts.pop();
22+
if (parts.length > 0) parts[parts.length - 1] += part.slice(5);
23+
}
2124

2225
return {
2326
files: [file],

test/app/routes/blog.json.js renamed to test/app/routes/blog/index.json.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import posts from './blog/_posts.js';
1+
import posts from './_posts.js';
22

33
const contents = JSON.stringify(posts.map(post => {
44
return {

test/unit/create_routes.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,12 @@ describe('create_routes', () => {
296296
});
297297
}, /As of Sapper 0.14, 4xx.html and 5xx.html should be replaced with _error.html/);
298298
});
299+
300+
it('treats foo/index.json.js the same as foo.json.js', () => {
301+
const route = create_routes({
302+
files: ['foo/index.json.js']
303+
})[0];
304+
305+
assert.ok(route.test('/foo.json'));
306+
});
299307
});

0 commit comments

Comments
 (0)