diff --git a/core/server/helpers/ghost_foot.js b/core/server/helpers/ghost_foot.js index 5e0f45e4a1..706df4d07f 100644 --- a/core/server/helpers/ghost_foot.js +++ b/core/server/helpers/ghost_foot.js @@ -5,7 +5,6 @@ var proxy = require('./proxy'), _ = require('lodash'), SafeString = proxy.SafeString, - filters = proxy.filters, settingsCache = proxy.settingsCache; // We use the name ghost_foot to match the helper for consistency: @@ -22,9 +21,5 @@ module.exports = function ghost_foot(options) { // eslint-disable-line camelcase foot.push(postCodeinjection); } - return filters - .doFilter('ghost_foot', foot) - .then(function (foot) { - return new SafeString(foot.join(' ').trim()); - }); + return new SafeString(foot.join(' ').trim()); }; diff --git a/core/server/helpers/ghost_head.js b/core/server/helpers/ghost_head.js index 90a68a3dec..e8addf21c9 100644 --- a/core/server/helpers/ghost_head.js +++ b/core/server/helpers/ghost_head.js @@ -10,7 +10,6 @@ var proxy = require('./proxy'), getAssetUrl = proxy.metaData.getAssetUrl, escapeExpression = proxy.escapeExpression, SafeString = proxy.SafeString, - filters = proxy.filters, logging = proxy.logging, settingsCache = proxy.settingsCache, config = proxy.config, @@ -191,9 +190,6 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase head.push(postCodeInjection); } } - return filters.doFilter('ghost_head', head); - }) - .then(function afterFilters(head) { debug('end'); return new SafeString(head.join('\n ').trim()); }) diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index ae3660d7f6..43ba3b2c61 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -48,6 +48,7 @@ registerAllCoreHelpers = function registerAllCoreHelpers() { registerThemeHelper('encode', coreHelpers.encode); registerThemeHelper('excerpt', coreHelpers.excerpt); registerThemeHelper('foreach', coreHelpers.foreach); + registerThemeHelper('ghost_foot', coreHelpers.ghost_foot); registerThemeHelper('has', coreHelpers.has); registerThemeHelper('is', coreHelpers.is); registerThemeHelper('img_url', coreHelpers.img_url); @@ -68,7 +69,6 @@ registerAllCoreHelpers = function registerAllCoreHelpers() { registerThemeHelper('url', coreHelpers.url); // Async theme helpers - registerAsyncThemeHelper('ghost_foot', coreHelpers.ghost_foot); registerAsyncThemeHelper('ghost_head', coreHelpers.ghost_head); registerAsyncThemeHelper('next_post', coreHelpers.next_post); registerAsyncThemeHelper('prev_post', coreHelpers.prev_post); diff --git a/core/server/helpers/proxy.js b/core/server/helpers/proxy.js index 30415b699d..cef6bf96ef 100644 --- a/core/server/helpers/proxy.js +++ b/core/server/helpers/proxy.js @@ -43,9 +43,6 @@ module.exports = { // Labs utils for enabling/disabling helpers labs: require('../services/labs'), - // System for apps to hook into one day maybe - filters: require('../filters'), - // Things required from data/meta metaData: { get: require('../data/meta'), // ghost_head diff --git a/core/server/models/base/index.js b/core/server/models/base/index.js index 0793197f31..90f10740c7 100644 --- a/core/server/models/base/index.js +++ b/core/server/models/base/index.js @@ -15,7 +15,6 @@ const _ = require('lodash'), db = require('../../data/db'), common = require('../../lib/common'), security = require('../../lib/security'), - filters = require('../../filters'), schema = require('../../data/schema'), urlService = require('../../services/url'), validation = require('../../data/validation'), @@ -1118,20 +1117,17 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ } } - // Check the filtered slug doesn't match any of the reserved keywords - return filters.doFilter('slug.reservedSlugs', config.get('slugs').reserved).then(function then(slugList) { - // Some keywords cannot be changed - slugList = _.union(slugList, urlService.utils.getProtectedSlugs()); + // Some keywords cannot be changed + const slugList = _.union(config.get('slugs').reserved, urlService.utils.getProtectedSlugs()); + slug = _.includes(slugList, slug) ? slug + '-' + baseName : slug; - return _.includes(slugList, slug) ? slug + '-' + baseName : slug; - }).then(function then(slug) { - // if slug is empty after trimming use the model name - if (!slug) { - slug = baseName; - } - // Test for duplicate slugs. - return checkIfSlugExists(slug); - }); + // if slug is empty after trimming use the model name + if (!slug) { + slug = baseName; + } + + // Test for duplicate slugs. + return checkIfSlugExists(slug); }, parseOrderOption: function (order, withRelated) { diff --git a/core/server/services/routing/controllers/channel.js b/core/server/services/routing/controllers/channel.js index 993018faec..8b6903cb81 100644 --- a/core/server/services/routing/controllers/channel.js +++ b/core/server/services/routing/controllers/channel.js @@ -3,7 +3,6 @@ const _ = require('lodash'), common = require('../../../lib/common'), security = require('../../../lib/security'), themes = require('../../themes'), - filters = require('../../../filters'), helpers = require('../helpers'); // @TODO: the collection+rss controller does almost the same @@ -56,13 +55,8 @@ module.exports = function channelController(req, res, next) { helpers.secure(req, data); }); - // @TODO: properly design these filters - filters.doFilter('prePostsRender', result.posts, res.locals) - .then(function (posts) { - result.posts = posts; - return result; - }) - .then(helpers.renderEntries(req, res)); + const renderer = helpers.renderEntries(req, res); + return renderer(result); }) .catch(helpers.handleError(next)); }; diff --git a/core/server/services/routing/controllers/collection.js b/core/server/services/routing/controllers/collection.js index f589683d06..4d94e37a76 100644 --- a/core/server/services/routing/controllers/collection.js +++ b/core/server/services/routing/controllers/collection.js @@ -4,7 +4,6 @@ const _ = require('lodash'), security = require('../../../lib/security'), urlService = require('../../../services/url'), themes = require('../../themes'), - filters = require('../../../filters'), helpers = require('../helpers'); module.exports = function collectionController(req, res, next) { @@ -67,13 +66,8 @@ module.exports = function collectionController(req, res, next) { helpers.secure(req, data); }); - // @TODO: properly design these filters - filters.doFilter('prePostsRender', result.posts, res.locals) - .then(function (posts) { - result.posts = posts; - return result; - }) - .then(helpers.renderEntries(req, res)); + const renderer = helpers.renderEntries(req, res); + return renderer(result); }) .catch(helpers.handleError(next)); }; diff --git a/core/server/services/routing/controllers/entry.js b/core/server/services/routing/controllers/entry.js index 63ae7f1967..79319de05a 100644 --- a/core/server/services/routing/controllers/entry.js +++ b/core/server/services/routing/controllers/entry.js @@ -1,7 +1,6 @@ const debug = require('ghost-ignition').debug('services:routing:controllers:entry'), url = require('url'), urlService = require('../../url'), - filters = require('../../../filters'), helpers = require('../helpers'); /** @@ -81,8 +80,8 @@ module.exports = function entryController(req, res, next) { helpers.secure(req, entry); - filters.doFilter('prePostsRender', entry, res.locals) - .then(helpers.renderEntry(req, res)); + const renderer = helpers.renderEntry(req, res); + return renderer(entry); }) .catch(helpers.handleError(next)); }; diff --git a/core/server/services/routing/controllers/preview.js b/core/server/services/routing/controllers/preview.js index 27de5fa156..e6d4b5c8e2 100644 --- a/core/server/services/routing/controllers/preview.js +++ b/core/server/services/routing/controllers/preview.js @@ -1,6 +1,5 @@ const debug = require('ghost-ignition').debug('services:routing:controllers:preview'), urlService = require('../../url'), - filters = require('../../../filters'), helpers = require('../helpers'); module.exports = function previewController(req, res, next) { @@ -14,7 +13,7 @@ module.exports = function previewController(req, res, next) { include: 'author,authors,tags' }; - api[res.routerOptions.query.controller] + return api[res.routerOptions.query.controller] .read(params) .then(function then(result) { const post = result[res.routerOptions.query.resource][0]; @@ -41,8 +40,8 @@ module.exports = function previewController(req, res, next) { helpers.secure(req, post); - filters.doFilter('prePostsRender', post, res.locals) - .then(helpers.renderEntry(req, res)); + const renderer = helpers.renderEntry(req, res); + return renderer(post); }) .catch(helpers.handleError(next)); }; diff --git a/core/server/services/rss/generate-feed.js b/core/server/services/rss/generate-feed.js index ad5760d80e..1f0f057a2b 100644 --- a/core/server/services/rss/generate-feed.js +++ b/core/server/services/rss/generate-feed.js @@ -2,7 +2,6 @@ var downsize = require('downsize'), Promise = require('bluebird'), RSS = require('rss'), urlService = require('../../services/url'), - filters = require('../../filters'), generateFeed, generateItem, generateTags; @@ -90,14 +89,10 @@ generateFeed = function generateFeed(baseUrl, data) { return data.posts.reduce((feedPromise, post) => { return feedPromise.then(() => { const item = generateItem(post, siteUrl, data.secure); - return filters.doFilter('rss.item', item, post).then((item) => { - return feed.item(item); - }); + return feed.item(item); }); }, Promise.resolve()).then(() => { - return filters.doFilter('rss.feed', feed).then((feed) => { - return feed.xml(); - }); + return feed.xml(); }); }; diff --git a/core/test/unit/helpers/ghost_foot_spec.js b/core/test/unit/helpers/ghost_foot_spec.js index 40f14280a8..649a871fb1 100644 --- a/core/test/unit/helpers/ghost_foot_spec.js +++ b/core/test/unit/helpers/ghost_foot_spec.js @@ -15,21 +15,18 @@ describe('{{ghost_foot}} helper', function () { settingsCacheStub = sinon.stub(settingsCache, 'get'); }); - it('outputs global injected code', function (done) { + it('outputs global injected code', function () { settingsCacheStub.withArgs('ghost_foot').returns(''); - helpers.ghost_foot({data: {}}).then(function (rendered) { - should.exist(rendered); - rendered.string.should.match(/'); - helpers.ghost_foot({ + const rendered = helpers.ghost_foot({ data: { root: { post: { @@ -37,19 +34,16 @@ describe('{{ghost_foot}} helper', function () { } } } - }).then(function (rendered) { - should.exist(rendered); - rendered.string.should.match(/'); - helpers.ghost_foot({ + const rendered = helpers.ghost_foot({ data: { root: { post: { @@ -57,19 +51,16 @@ describe('{{ghost_foot}} helper', function () { } } } - }).then(function (rendered) { - should.exist(rendered); - rendered.string.should.match(/'); - helpers.ghost_foot({ + const rendered = helpers.ghost_foot({ data: { root: { post: { @@ -77,34 +68,25 @@ describe('{{ghost_foot}} helper', function () { } } } - }).then(function (rendered) { - should.exist(rendered); - rendered.string.should.match(/