mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-20 06:15:15 +00:00
Merge pull request #301 from sveltejs/gh-297
treat foo/index.json.js as foo.json.js
This commit is contained in:
@@ -17,7 +17,10 @@ export default function create_routes({ files } = { files: glob.sync('**/*.*', {
|
|||||||
|
|
||||||
const base = file.replace(/\.[^/.]+$/, '');
|
const base = file.replace(/\.[^/.]+$/, '');
|
||||||
const parts = base.split('/'); // glob output is always posix-style
|
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 {
|
return {
|
||||||
files: [file],
|
files: [file],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import posts from './blog/_posts.js';
|
import posts from './_posts.js';
|
||||||
|
|
||||||
const contents = JSON.stringify(posts.map(post => {
|
const contents = JSON.stringify(posts.map(post => {
|
||||||
return {
|
return {
|
||||||
@@ -296,4 +296,12 @@ describe('create_routes', () => {
|
|||||||
});
|
});
|
||||||
}, /As of Sapper 0.14, 4xx.html and 5xx.html should be replaced with _error.html/);
|
}, /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'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user