mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Dynamic Routing Beta: Added resource config
refs #9601 - outsource resource config - we will re-use it in the yaml validator
This commit is contained in:
parent
d0f2b3e7ad
commit
4280fa3c58
2 changed files with 58 additions and 33 deletions
|
@ -5,35 +5,7 @@ const RSSRouter = require('./RSSRouter');
|
|||
const urlService = require('../url');
|
||||
const controllers = require('./controllers');
|
||||
const middlewares = require('./middlewares');
|
||||
|
||||
/* eslint-disable */
|
||||
const knownTaxonomies = {
|
||||
tag: {
|
||||
filter: "tags:'%s'+tags.visibility:public",
|
||||
data: {
|
||||
type: 'read',
|
||||
resource: 'tags',
|
||||
options: {
|
||||
slug: '%s',
|
||||
visibility: 'public'
|
||||
}
|
||||
},
|
||||
editRedirect: '#/settings/tags/:slug/'
|
||||
},
|
||||
author: {
|
||||
filter: "authors:'%s'",
|
||||
data: {
|
||||
type: 'read',
|
||||
resource: 'users',
|
||||
options: {
|
||||
slug: '%s',
|
||||
visibility: 'public'
|
||||
}
|
||||
},
|
||||
editRedirect: '#/team/:slug/'
|
||||
}
|
||||
};
|
||||
/* eslint-enable */
|
||||
const RESOURCE_CONFIG = require('./assets/resource-config');
|
||||
|
||||
class TaxonomyRouter extends ParentRouter {
|
||||
constructor(key, permalinks) {
|
||||
|
@ -77,8 +49,8 @@ class TaxonomyRouter extends ParentRouter {
|
|||
res.locals.routerOptions = {
|
||||
name: this.taxonomyKey,
|
||||
permalinks: this.permalinks.getValue(),
|
||||
data: {[this.taxonomyKey]: knownTaxonomies[this.taxonomyKey].data},
|
||||
filter: knownTaxonomies[this.taxonomyKey].filter,
|
||||
data: {[this.taxonomyKey]: _.omit(RESOURCE_CONFIG.QUERY[this.taxonomyKey], 'alias')},
|
||||
filter: RESOURCE_CONFIG.TAXONOMIES[this.taxonomyKey].filter,
|
||||
type: this.getType(),
|
||||
context: [this.taxonomyKey],
|
||||
slugTemplate: true,
|
||||
|
@ -93,11 +65,11 @@ class TaxonomyRouter extends ParentRouter {
|
|||
}
|
||||
|
||||
_redirectEditOption(req, res) {
|
||||
urlService.utils.redirectToAdmin(302, res, knownTaxonomies[this.taxonomyKey].editRedirect.replace(':slug', req.params.slug));
|
||||
urlService.utils.redirectToAdmin(302, res, RESOURCE_CONFIG.TAXONOMIES[this.taxonomyKey].editRedirect.replace(':slug', req.params.slug));
|
||||
}
|
||||
|
||||
getType() {
|
||||
return knownTaxonomies[this.taxonomyKey].data.resource;
|
||||
return RESOURCE_CONFIG.QUERY[this.taxonomyKey].resource;
|
||||
}
|
||||
|
||||
getRoute() {
|
||||
|
|
53
core/server/services/routing/assets/resource-config.js
Normal file
53
core/server/services/routing/assets/resource-config.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* eslint-disable */
|
||||
module.exports.QUERY = {
|
||||
tag: {
|
||||
alias: 'tags',
|
||||
type: 'read',
|
||||
resource: 'tags',
|
||||
options: {
|
||||
slug: '%s',
|
||||
visibility: 'public'
|
||||
}
|
||||
},
|
||||
author: {
|
||||
alias: 'users',
|
||||
type: 'read',
|
||||
resource: 'users',
|
||||
options: {
|
||||
slug: '%s',
|
||||
visibility: 'public'
|
||||
}
|
||||
},
|
||||
post: {
|
||||
alias: 'posts',
|
||||
type: 'read',
|
||||
resource: 'posts',
|
||||
options: {
|
||||
slug: '%s',
|
||||
status: 'published',
|
||||
page: 0
|
||||
}
|
||||
},
|
||||
page: {
|
||||
alias: 'pages',
|
||||
type: 'read',
|
||||
resource: 'posts',
|
||||
options: {
|
||||
slug: '%s',
|
||||
status: 'published',
|
||||
page: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.TAXONOMIES = {
|
||||
tag: {
|
||||
filter: 'tags:\'%s\'+tags.visibility:public',
|
||||
editRedirect: '#/settings/tags/:slug/'
|
||||
},
|
||||
author: {
|
||||
filter: 'authors:\'%s\'',
|
||||
editRedirect: '#/team/:slug/'
|
||||
}
|
||||
};
|
||||
/* eslint-enable */
|
Loading…
Add table
Reference in a new issue