From 03b0139ef945b1ebe3f05607d8fca7f08bfbb785 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe <github.erisds@gmail.com> Date: Fri, 27 May 2022 15:07:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20page=20to=20be=20used=20as?= =?UTF-8?q?=20post=20in=20dynamic=20routing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes: https://github.com/TryGhost/Ghost/issues/10042 closes: https://github.com/TryGhost/Ghost/issues/14206 - the fact that pages are exposed as .page in dynamic routing has never played nicely - this fix changes nothing in the tests - which shows this was never a covered case - ideally I should add some tests, but for now this tiny change should prevent a lot of dynamic routing pain - note, it doesn't remove .page, it just adds .post, so both work --- core/frontend/services/rendering/format-response.js | 6 +++++- core/frontend/services/routing/controllers/static.js | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/frontend/services/rendering/format-response.js b/core/frontend/services/rendering/format-response.js index 48d70d5cee..98d02da0e9 100644 --- a/core/frontend/services/rendering/format-response.js +++ b/core/frontend/services/rendering/format-response.js @@ -6,7 +6,7 @@ const {prepareContextResource} = require('../proxy'); * * @return {Object} containing page variables */ -function formatPageResponse(result) { +function formatPageResponse(result, pageAsPost = false) { const response = {}; if (result.posts) { @@ -32,6 +32,10 @@ function formatPageResponse(result) { } }); + if (pageAsPost && response.page) { + response.post = response.page; + } + return response; } diff --git a/core/frontend/services/routing/controllers/static.js b/core/frontend/services/routing/controllers/static.js index 2ac32e3316..9df5a62010 100644 --- a/core/frontend/services/routing/controllers/static.js +++ b/core/frontend/services/routing/controllers/static.js @@ -60,7 +60,10 @@ module.exports = function staticController(req, res, next) { }); } - renderer.renderer(req, res, renderer.formatResponse.entries(response)); + // This flag solves the confusion about whether the output contains a post or page object by duplicating the objects + // This is not ideal, but will solve some long standing pain points with dynamic routing until we can overhaul it + const duplicatePagesAsPosts = true; + renderer.renderer(req, res, renderer.formatResponse.entries(response, duplicatePagesAsPosts)); }) .catch(renderer.handleError(next)); };