mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36: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('.');
|
let [resourceKey, slug] = shortForm.split('.');
|
||||||
|
|
||||||
longForm.query[options.resourceKey || resourceKey] = {};
|
longForm.query[options.resourceKey || resourceKey] = {};
|
||||||
longForm.query[options.resourceKey || resourceKey] = _.omit(_.cloneDeep(RESOURCE_CONFIG.QUERY[resourceKey]), 'alias');
|
longForm.query[options.resourceKey || resourceKey] = _.omit(_.cloneDeep(RESOURCE_CONFIG.QUERY[resourceKey]), 'alias');
|
||||||
|
|
||||||
|
// redirect is enabled by default when using the short form
|
||||||
longForm.router = {
|
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;
|
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 allowedQueryOptions = ['limit', 'filter', 'include', 'slug', 'visibility', 'status'];
|
||||||
const allowedRouterOptions = ['redirect', 'slug'];
|
const allowedRouterOptions = ['redirect', 'slug'];
|
||||||
const defaultRouterOptions = {
|
const defaultRouterOptions = {
|
||||||
redirect: false
|
redirect: true
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
|
|
|
@ -1267,12 +1267,13 @@ describe('Integration - Web - Site', function () {
|
||||||
resource: 'users',
|
resource: 'users',
|
||||||
type: 'read',
|
type: 'read',
|
||||||
options: {
|
options: {
|
||||||
slug: 'joe-bloggs'
|
slug: 'joe-bloggs',
|
||||||
|
redirect: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
users: [{redirect: true, slug: 'joe-bloggs'}]
|
users: [{redirect: false, slug: 'joe-bloggs'}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1290,12 +1291,13 @@ describe('Integration - Web - Site', function () {
|
||||||
resource: 'users',
|
resource: 'users',
|
||||||
type: 'read',
|
type: 'read',
|
||||||
options: {
|
options: {
|
||||||
slug: 'joe-bloggs'
|
slug: 'joe-bloggs',
|
||||||
|
redirect: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
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)
|
return testUtils.mocks.express.invoke(app, req)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
response.statusCode.should.eql(301);
|
response.statusCode.should.eql(200);
|
||||||
response.headers.location.should.eql('/channel3/');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -323,7 +323,6 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
'/food/': {
|
'/food/': {
|
||||||
data: 'tag.food'
|
data: 'tag.food'
|
||||||
},
|
},
|
||||||
// @TODO: enable redirect
|
|
||||||
'/music/': {
|
'/music/': {
|
||||||
data: 'tag.music'
|
data: 'tag.music'
|
||||||
},
|
},
|
||||||
|
@ -370,7 +369,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
tags: [{redirect: false, slug: 'food'}]
|
tags: [{redirect: true, slug: 'food'}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -388,7 +387,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
tags: [{redirect: false, slug: 'music'}]
|
tags: [{redirect: true, slug: 'music'}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -414,7 +413,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
tags: [{redirect: false, slug: 'bed'}, {redirect: false, slug: 'dream'}]
|
tags: [{redirect: true, slug: 'bed'}, {redirect: true, slug: 'dream'}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -436,7 +435,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
pages: [{redirect: false, slug: 'home'}]
|
pages: [{redirect: true, slug: 'home'}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -455,7 +454,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
tags: [{redirect: false, slug: 'something'}]
|
tags: [{redirect: true, slug: 'something'}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -474,7 +473,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
tags: [{redirect: false, slug: 'sport'}]
|
tags: [{redirect: true, slug: 'sport'}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -499,7 +498,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
posts: {
|
posts: {
|
||||||
resource: 'posts',
|
resource: 'posts',
|
||||||
type: 'read',
|
type: 'read',
|
||||||
redirect: true
|
redirect: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -542,7 +541,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
posts: [{redirect: false}]
|
posts: [{redirect: true}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -561,7 +560,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
posts: [{redirect: true}]
|
posts: [{redirect: false}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
@ -601,7 +600,7 @@ describe('UNIT: services/settings/validate', function () {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
router: {
|
router: {
|
||||||
posts: [{redirect: false, slug: 'ups'}]
|
posts: [{redirect: true, slug: 'ups'}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
templates: []
|
templates: []
|
||||||
|
|
Loading…
Add table
Reference in a new issue