0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Fixed collections card rendering drafts in front-end output (#18166)

no issue

- added missing `context.public = true` option that tells our data fetching layer that this is a "Frontend/Content API" request and relevant filters should be applied
- adjusted require of posts service so it's only grabbed on the first render rather than every render
This commit is contained in:
Kevin Ansfield 2023-09-15 12:16:35 +01:00 committed by GitHub
parent 7f7185333e
commit a750ed847c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ const storage = require('../adapters/storage');
let nodes;
let lexicalHtmlRenderer;
let urlTransformMap;
let postsService;
function populateNodes() {
const {DEFAULT_NODES} = require('@tryghost/kg-default-nodes');
@ -28,12 +29,19 @@ module.exports = {
},
async render(lexical, userOptions = {}) {
const getPostServiceInstance = require('../services/posts/posts-service');
const postsService = getPostServiceInstance();
if (!postsService) {
const getPostServiceInstance = require('../services/posts/posts-service');
postsService = getPostServiceInstance();
}
const getCollectionPosts = async (collectionSlug, postCount) => {
const transacting = userOptions.transacting;
const {data} = await postsService.browsePosts({collection: collectionSlug, limit: postCount, transacting});
const {data} = await postsService.browsePosts({
context: {public: true}, // mimic Content API request
collection: collectionSlug,
limit: postCount,
transacting
});
let posts = data.map(p => p.toJSON());
return posts;
};