mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
🎨 Dynamic Routing Beta: Enabled redirect by default when using data
key
refs #9601 - when using the short form `data: tag.welcome` the redirect is enabled by default - /tag/welcome/ will redirect to the channel/collection which makes use of the data key - you can disable the redirect by using the long form e.g. data: tag: resource: tags type: read slug: welcome redirect: false
This commit is contained in:
parent
220d0456b4
commit
17833a669b
3 changed files with 20 additions and 28 deletions
|
@ -46,22 +46,14 @@ _private.validateData = function validateData(object) {
|
|||
});
|
||||
}
|
||||
|
||||
let redirect = false;
|
||||
|
||||
// CASE: user wants to redirect traffic from resource to route
|
||||
// @TODO: enable redirect feature if confirmed
|
||||
if (false && shortForm.match(/^->/)) { // eslint-disable-line no-constant-condition
|
||||
shortForm = shortForm.replace(/^->/, '');
|
||||
redirect = true;
|
||||
}
|
||||
|
||||
let [resourceKey, slug] = shortForm.split('.');
|
||||
|
||||
longForm.query[options.resourceKey || resourceKey] = {};
|
||||
longForm.query[options.resourceKey || resourceKey] = _.omit(_.cloneDeep(RESOURCE_CONFIG.QUERY[resourceKey]), 'alias');
|
||||
|
||||
// redirect is enabled by default when using the short form
|
||||
longForm.router = {
|
||||
[RESOURCE_CONFIG.QUERY[resourceKey].alias]: [{slug: slug, redirect: redirect}]
|
||||
[RESOURCE_CONFIG.QUERY[resourceKey].alias]: [{slug: slug, redirect: true}]
|
||||
};
|
||||
|
||||
longForm.query[options.resourceKey || resourceKey].options.slug = slug;
|
||||
|
@ -80,7 +72,7 @@ _private.validateData = function validateData(object) {
|
|||
const allowedQueryOptions = ['limit', 'filter', 'include', 'slug', 'visibility', 'status'];
|
||||
const allowedRouterOptions = ['redirect', 'slug'];
|
||||
const defaultRouterOptions = {
|
||||
redirect: false
|
||||
redirect: true
|
||||
};
|
||||
|
||||
let data = {
|
||||
|
|
|
@ -1267,12 +1267,13 @@ describe('Integration - Web - Site', function () {
|
|||
resource: 'users',
|
||||
type: 'read',
|
||||
options: {
|
||||
slug: 'joe-bloggs'
|
||||
slug: 'joe-bloggs',
|
||||
redirect: false
|
||||
}
|
||||
}
|
||||
},
|
||||
router: {
|
||||
users: [{redirect: true, slug: 'joe-bloggs'}]
|
||||
users: [{redirect: false, slug: 'joe-bloggs'}]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1290,12 +1291,13 @@ describe('Integration - Web - Site', function () {
|
|||
resource: 'users',
|
||||
type: 'read',
|
||||
options: {
|
||||
slug: 'joe-bloggs'
|
||||
slug: 'joe-bloggs',
|
||||
redirect: false
|
||||
}
|
||||
}
|
||||
},
|
||||
router: {
|
||||
users: [{redirect: true, slug: 'joe-bloggs'}]
|
||||
users: [{redirect: false, slug: 'joe-bloggs'}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1478,8 +1480,7 @@ describe('Integration - Web - Site', function () {
|
|||
|
||||
return testUtils.mocks.express.invoke(app, req)
|
||||
.then(function (response) {
|
||||
response.statusCode.should.eql(301);
|
||||
response.headers.location.should.eql('/channel3/');
|
||||
response.statusCode.should.eql(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -323,7 +323,6 @@ describe('UNIT: services/settings/validate', function () {
|
|||
'/food/': {
|
||||
data: 'tag.food'
|
||||
},
|
||||
// @TODO: enable redirect
|
||||
'/music/': {
|
||||
data: 'tag.music'
|
||||
},
|
||||
|
@ -370,7 +369,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
tags: [{redirect: false, slug: 'food'}]
|
||||
tags: [{redirect: true, slug: 'food'}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -388,7 +387,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
tags: [{redirect: false, slug: 'music'}]
|
||||
tags: [{redirect: true, slug: 'music'}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -414,7 +413,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
tags: [{redirect: false, slug: 'bed'}, {redirect: false, slug: 'dream'}]
|
||||
tags: [{redirect: true, slug: 'bed'}, {redirect: true, slug: 'dream'}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -436,7 +435,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
pages: [{redirect: false, slug: 'home'}]
|
||||
pages: [{redirect: true, slug: 'home'}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -455,7 +454,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
tags: [{redirect: false, slug: 'something'}]
|
||||
tags: [{redirect: true, slug: 'something'}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -474,7 +473,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
tags: [{redirect: false, slug: 'sport'}]
|
||||
tags: [{redirect: true, slug: 'sport'}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -499,7 +498,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
posts: {
|
||||
resource: 'posts',
|
||||
type: 'read',
|
||||
redirect: true
|
||||
redirect: false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -542,7 +541,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
posts: [{redirect: false}]
|
||||
posts: [{redirect: true}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -561,7 +560,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
posts: [{redirect: true}]
|
||||
posts: [{redirect: false}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
@ -601,7 +600,7 @@ describe('UNIT: services/settings/validate', function () {
|
|||
}
|
||||
},
|
||||
router: {
|
||||
posts: [{redirect: false, slug: 'ups'}]
|
||||
posts: [{redirect: true, slug: 'ups'}]
|
||||
}
|
||||
},
|
||||
templates: []
|
||||
|
|
Loading…
Add table
Reference in a new issue