mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
✨ Allow page to be used as post in dynamic routing
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
This commit is contained in:
parent
17bb55118a
commit
03b0139ef9
2 changed files with 9 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue