From 5abd67809d21ce3f2365cab4d8e9de2d905cfb71 Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 17 May 2022 11:39:43 +0800 Subject: [PATCH] Cleaned up AMP rendering of "page" resources refs https://github.com/TryGhost/Toolbox/issues/332 - After dropping support for `page: (true|false)` for post resources in Content API there is no need to check for `body.post.page` in the AMP renderer. Furthermore, the AMP router uses `public-post` controller that **only** returns "post" resources. This check was a redundant, unnecessary piece of logic --- core/frontend/apps/amp/lib/router.js | 5 ++--- test/unit/frontend/apps/amp/router.test.js | 14 -------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/core/frontend/apps/amp/lib/router.js b/core/frontend/apps/amp/lib/router.js index 443e25c5a6..fe159ee308 100644 --- a/core/frontend/apps/amp/lib/router.js +++ b/core/frontend/apps/amp/lib/router.js @@ -26,8 +26,7 @@ function _renderer(req, res, next) { // Format data let body = req.body || {}; - // CASE: we only support amp pages for posts that are not static pages - if (!body.post || body.post.page) { + if (!body.post) { return next(new errors.NotFoundError({message: tpl(messages.pageNotFound)})); } @@ -70,7 +69,7 @@ function getPostData(req, res, next) { })); } - // @NOTE: amp is not supported for static pages + // @NOTE: amp is not supported for "page" resource // @TODO: https://github.com/TryGhost/Ghost/issues/10548 dataService.entryLookup(urlWithoutSubdirectoryWithoutAmp, {permalinks, query: {controller: 'postsPublic', resource: 'posts'}}, res.locals) .then((result) => { diff --git a/test/unit/frontend/apps/amp/router.test.js b/test/unit/frontend/apps/amp/router.test.js index ec811d62bb..3f73056460 100644 --- a/test/unit/frontend/apps/amp/router.test.js +++ b/test/unit/frontend/apps/amp/router.test.js @@ -77,20 +77,6 @@ describe('Unit - apps/amp/lib/router', function () { done(); }); }); - - it('throws 404 when req.body.post is a page', function (done) { - req.body = { - post: { - page: true - } - }; - - ampController.renderer(req, res, function (err) { - (err instanceof errors.NotFoundError).should.be.true(); - renderer.renderer.called.should.be.false(); - done(); - }); - }); }); describe('fn: getPostData', function () {