treat foo/index.json.js as foo.json.js - fixes #297

This commit is contained in:
Rich Harris
2018-06-28 13:20:41 -04:00
parent 5b5f33d3cf
commit b7bb4db8c1
3 changed files with 13 additions and 2 deletions

View File

@@ -17,7 +17,10 @@ export default function create_routes({ files } = { files: glob.sync('**/*.*', {
const base = file.replace(/\.[^/.]+$/, '');
const parts = base.split('/'); // glob output is always posix-style
if (parts[parts.length - 1] === 'index') parts.pop();
if (/^index(\..+)?/.test(parts[parts.length - 1])) {
const part = parts.pop();
if (parts.length > 0) parts[parts.length - 1] += part.slice(5);
}
return {
files: [file],

View File

@@ -1,4 +1,4 @@
import posts from './blog/_posts.js';
import posts from './_posts.js';
const contents = JSON.stringify(posts.map(post => {
return {

View File

@@ -296,4 +296,12 @@ describe('create_routes', () => {
});
}, /As of Sapper 0.14, 4xx.html and 5xx.html should be replaced with _error.html/);
});
it('treats foo/index.json.js the same as foo.json.js', () => {
const route = create_routes({
files: ['foo/index.json.js']
})[0];
assert.ok(route.test('/foo.json'));
});
});